2012-12-19 3 views
1

중단이 사실로 끝나서 시작으로 돌아 가지 않는 이유는 무엇입니까?파이썬 중단 기능이 true로 끝나지 않습니다.

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") 

저는 파이썬에 매우 익숙해서 용어의 단순한 오용이라고 생각합니다.

+2

'answer1 = "True"와 "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") 
관련 문제