Python break函数不会在true时结束

1 python break while-loop

为什么休息时间不会结束,而是回到起点?

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")
Run Code Online (Sandbox Code Playgroud)

我对python很新,所以我认为它只是对这些术语的简单滥用.

Yuv*_*dam 5

break存在整个while循环.

continue是你正在寻找的,回到下一个while迭代.

你可以阅读更多关于控制流程的工具,breakcontinue在官方文档:http://docs.python.org/2/tutorial/controlflow.html#break-and-continue-statements-and-else-clauses-on-loops

(你也有其他错误,正如其他人提到的那样)