How do I make python go back in code?
So basically, I am trying to create a game. Its going good so far! However, I am trying to figure out how to make code go back. I am a beginner at python, so I think its something to do with def start(): and start():, or something along those lines, but I'm not sure. If you do not know what I am talking about, I am basically saying I want something like:
(1) if (variable) == (whatever)
(2) print ("Cool you win")
(4) (code to go back and repeat line 1)
(5) else:
(6) print ("You loose!")
(7) (code to go back and repeat line 1)
so basically like a loop. So, how can I do this?
You want to use a while loop
while <condition>:
(1) if (variable == whatever):
(2) print ("Cool you win")
(4) #nothing needed here
(5) else:
(6) print ("You loose!")
(7) #nothing needed here
If you don't have a particular condition, you can just loop forever with while True:
上一篇: Grep只匹配特定的行,但保持上下文
下一篇: 如何让python回到代码中?