Python break 函数在 true 时不会结束 [英] Python break function doesn't end while true
问题描述
为什么break不会结束while true并返回开始?
Why will the break not end the while true and return to the start?
while True:
print('This is a quiz')
print('What is your name?')
Name = input()
print('Hello ' + Name + ', The quiz will now begin')
import time
time.sleep(2)
question1 = "Question one: "
answer1 = "True" and "true"
print(question1)
qanswer = input()
if qanswer != answer1:
print('Sorry, the answer is: ' + answer1)
break
if answer1 == qanswer:
print("Correct! Here's the next question")
我对 python 还很陌生,所以我认为这只是对术语的简单误用.
I'm pretty new to python so I assume it's just a simple misuse of the terms.
推荐答案
break
存在于整个 while
循环中.
break
exists the entire while
loop.
continue
就是你要找的,返回到下一个 while
迭代.
continue
is what you're looking for, returning to the next while
iteration.
您可以在官方文档中阅读有关控制流工具的更多信息,break
和 continue
:http://docs.python.org/2/tutorial/controlflow.html#break-and-continue-statements-and-else-clauses-on-loops
You can read more about control flow tools, break
and continue
in the official docs: http://docs.python.org/2/tutorial/controlflow.html#break-and-continue-statements-and-else-clauses-on-loops
(您还有其他一些错误,正如其他人正确提到的那样)
(You also have some other bugs as others have mentioned correctly)
这篇关于Python break 函数在 true 时不会结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!