Python中断函数不使用';如果是真的,就不要结束
为什么中断不会结束,而为真并返回开始Python中断函数不使用';如果是真的,就不要结束,python,while-loop,break,Python,While Loop,Break,为什么中断不会结束,而为真并返回开始 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 = "T
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非常陌生,所以我认为这只是对术语的简单误用。
break
存在整个while
循环
continue
是您正在寻找的,在迭代时返回到下一个
您可以在官方文档中阅读有关控制流工具、break
和continue
的更多信息:
(您还有一些其他错误,正如其他人正确提到的)中断
存在整个while
循环
continue
是您正在寻找的,在
迭代时返回到下一个
您可以在官方文档中阅读有关控制流工具、break
和continue
的更多信息:
(您还有其他一些错误,正如其他人正确提到的)使用“继续”关键字,而不是“中断”。使用“继续”关键字,而不是“中断”。answer1=“True”和“True”
这并不是您所认为的那样。创建变量后,请尝试打印answer1
。如果要将用户输入与两个不同的字符串进行比较,则需要将输入与两个字符串进行比较。我不认为这意味着你认为它意味着什么:answer1=“True”和“True”
answer1=“True”和“True”
这不是你认为的那样。创建变量后,请尝试打印answer1
。如果要将用户输入与两个不同的字符串进行比较,则需要将输入与两个字符串进行比较。我不认为这意味着你认为它的意思:answer1=“True”和“True”
。
....
answer1 = ["True", "true"]
...
if not(qanswer in answer1):
print('Sorry, the answer is: ' + answer1)
break
else:
print("Correct! Here's the next question")