2012-12-19 52 views
1

爲什麼這個中斷不會結束,而是返回到開始?Python中斷函數並沒有結束,而是真的

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很新,所以我認爲這只是一個簡單的濫用條款。

+2

'answer1 =「True」and「true」'這不符合你的想法。嘗試在創建變量後打印「answer1」。如果要將用戶輸入與兩個不同的字符串進行比較,則需要將輸入與兩個字符串進行比較。 [文檔和](http://docs.python.org/2/library/stdtypes.html#boolean-operations-and-or-not) – unholysampler

+0

我不認爲這意味着你的想法:'answer1 =「真」和「真」'。 –

回答

0

使用「繼續」關鍵字,不「打破」。

0
.... 
answer1 = ["True", "true"] 
... 
if not(qanswer in answer1): 
    print('Sorry, the answer is: ' + answer1) 
    break 
else: 
    print("Correct! Here's the next question") 
相關問題