+ 1

Question about python ā€œwhileā€ command

Help!!! So I’m trying to use the def and while in the following code. The idea of using ā€œwhileā€ is that the person can keep imputing the color. But for some reason, it only works for the first input. Please help! ###Let's play a game: guess my favorite color. please input color and if you give up, input "give up".### def myfav(color): if color == "red": print (color + " is my favorite color") else: print ("not my fav") while True: x=input ("color name: ") if x == "give up": print ("My fav color is red.") break else: print (x) myfav (x)

3rd Jun 2019, 8:02 PM
Yang Yang
Yang Yang - avatar
8 Antwoorden
+ 1
Are you running the code on Sololearn?
3rd Jun 2019, 8:11 PM
Juho Pesonen
Juho Pesonen - avatar
+ 1
Yang Yang Sololearn will ask for input only once. Multiple inputs are seperated by a new line if I remember correctly. Sublime text doesn’t support input.
3rd Jun 2019, 8:19 PM
Juho Pesonen
Juho Pesonen - avatar
0
yes. does Sololearn only allow input once? Sublime on my mac doesn’t run ā€œinputā€ at all. Any advice, please? Thank you! Goodester
3rd Jun 2019, 8:12 PM
Yang Yang
Yang Yang - avatar
0
Yang Yang Well that could be the problem. Try to run it on some other place.
3rd Jun 2019, 8:15 PM
Juho Pesonen
Juho Pesonen - avatar
0
Goodester I see. Thank you! Which one do you recommend, if not Sublime?
3rd Jun 2019, 8:21 PM
Yang Yang
Yang Yang - avatar
0
Yang Yang If you were asking for a good IDE/text editor, I’d recommend PyCharm for sure.
3rd Jun 2019, 8:24 PM
Juho Pesonen
Juho Pesonen - avatar
0
Goodester thank you!!
3rd Jun 2019, 8:25 PM
Yang Yang
Yang Yang - avatar
0
Yang Yang You’re welcome :)
3rd Jun 2019, 8:26 PM
Juho Pesonen
Juho Pesonen - avatar