193k views
0 votes
Create a Python program in a file named loops1.py that does the following: a. Use a while loop to keep asking the user for input until the length of the input is at least 10. b. When the user finally enters an input that is 10 or more characters, proceed as follows: i. If the length of the input is even, print the input string back in all lowercase. ii. If the length of the input is odd, print the input string back in all uppercase.

User Ahmettolga
by
4.6k points

2 Answers

4 votes

Answer:

myvalue = input("please input your value: ")

while len(myvalue) < 10 :

myvalue = input("please input your value: ")

if len(myvalue) >= 10:

break

if len(myvalue)%2 == 0:

print(myvalue.lower())

else:

print(myvalue.upper())

Step-by-step explanation:

Create a python program file and name the file as loops1.py in accordance to what the question stated. Note to run this file you must have installed python software on your system.

Interpreting the code,

myvalue = input("please input your value: ") simply prompt the user to input a value .

while len(myvalue) < 10 : and myvalue = input("please input your value: ") This is a while loop that prompts the user to input another values if the initial value length inputted is less than 10.

if len(myvalue) >= 10: If the length of the value is equal or greater than 10 then the break statement terminates the while loop entirely.

if len(myvalue)%2 == 0: If the length of the value inputted divided by 2 is equal to 0, the lower case version(print(myvalue.lower())) of the value is printed out.

else:

The uppercase value is printed( print(myvalue.upper()))

NOTE python use indentation.

User Let
by
5.1k points
4 votes

Answer:

mystr = input("Enter a string ")

length = len(mystr)

while length<10:

mystr = input("Enter a string ")

length = len(mystr)

if(length>=10):

break

if len(mystr)%2==0:

print(mystr.lower())

else:

print(mystr.upper())

Step-by-step explanation:

The variable mystr is used to save user's input which is received with the input function

A second variable length is used to save the length of the input string Using a while statement the user is continually prompted to enter a string while length is less than 10.

If length is greater or equal to 10. We check for even or odd using the modulo (%) operator.

We use lower() and upper() to change the case of the string

User El Danielo
by
4.8k points