Python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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)

29th Apr 2021, 3:52 AM
Elisa
5 Answers
+ 3
Your code is going to infinite loop. Hey, you are converting your input statement to lower case so plz you write "STOP" To lower case in while loop. So that it works properly
29th Apr 2021, 4:06 AM
Aysha
Aysha - avatar
+ 2
Try it in this way. This will surely work user_input = input("My hobbies are: ") while user_input !="STOP": user_input=input("what are your hobbies?") print(user_input.upper())
29th Apr 2021, 4:47 AM
Aysha
Aysha - avatar
+ 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())
30th Apr 2021, 4:49 AM
Tarun R Jain
Tarun R Jain - avatar
+ 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
29th Apr 2021, 4:27 AM
Artem 🇺🇦
Artem 🇺🇦 - avatar
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())
29th Apr 2021, 4:44 AM
Scarlet Witch
Scarlet Witch - avatar