+ 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?
5 Respostas
+ 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.
+ 2
no, you will fall into infinite loop, you need to have an update of the variable ans in the while code block.
+ 1
Thanks Gordon
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
0
Yes I know, I use PyCharm