+ 1
Python
Hey guys, I’m new to python and I’m trying to write a script that will take user input and will output everything in lowercase. The program should run until the client enters the word “STOP”. Can you please help? Thanks This is what I have so far: user_input=input("What are your hobbies?") print("My hobbies are: ", user_input.lower()) while user_input !="STOP": print(user_input)
5 Antworten
+ 2
The best way is to prompt the user input inside the while loop and use the if condition inside the while loop after the user inputs is prompted, if the user input is stop then exit.
print("What are your hobbies?")
hobby=list()
while True:
hobbies=input("")
if hobbies == "stop":
break
else:
hobby.append(hobbies)
print ("My hobbies are: ")
for hobbies in hobby:
print (hobbies.lower())
+ 1
What your script is doing is asking for user input once and printing it infinitely. If you want the program to exit when the user enters "STOP" you have to ask for user input inside your whole loop, like this:
https://code.sololearn.com/c6a09cEqds06/?ref=app
0
Is this is what you want?
user_input = input("My hobbies are: ")
while user_input !="STOP":
user_input=input("what are your hobbies?")
print(user_input.lower())