+ 1

Bucles / Loops

How I can do a loop that repeat a menu of my code?, Like this: ans = str(input()) while ans == "yes": print("my code goes here") It's correct?

7th Jan 2020, 4:09 PM
el3be
el3be - avatar
5 Antworten
+ 3
Leandro Blandi yes, you can use input to update ans, otherwise the condition is always true and you cannot quit the loop. For Sololearn code playground, this doesn't work. But in normal IDE on a computer, this works.
7th Jan 2020, 4:39 PM
Gordon
Gordon - avatar
+ 2
no, you will fall into infinite loop, you need to have an update of the variable ans in the while code block.
7th Jan 2020, 4:21 PM
Gordon
Gordon - avatar
+ 1
Thanks Gordon
7th Jan 2020, 4:47 PM
el3be
el3be - avatar
0
Gordon Do you say something like that: #def variable ans = str(input()) # while while ans == "yes": #updste variable that you say? ans = str(input()) # TODO CODE
7th Jan 2020, 4:24 PM
el3be
el3be - avatar
0
Yes I know, I use PyCharm
7th Jan 2020, 4:47 PM
el3be
el3be - avatar