+ 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)
8 Respuestas
+ 1
Are you running the code on Sololearn?
+ 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.
0
yes. does Sololearn only allow input once? Sublime on my mac doesn’t run “input” at all. Any advice, please? Thank you! Goodester
0
Yang Yang Well that could be the problem. Try to run it on some other place.
0
Goodester I see. Thank you! Which one do you recommend, if not Sublime?
0
Yang Yang If you were asking for a good IDE/text editor, I’d recommend PyCharm for sure.
0
Goodester thank you!!
0
Yang Yang You’re welcome :)