为什么“ stage + = 1”行不起作用?

时间:2019-07-26 08:26:23

标签: python

def start():
    questions = ['What is the capital of India ? ',
                 'World`s tallest statue is ?',
                 'Where is the Red Fort located ?',
                 '10! = ?',
                 'How many days are present in a Leap year ?']

first_option = ['Mumbai ', 'Statue of liberty', 'Agra ',
                '3,628,800', '365']

second_option = ['Delhi ', 'Statue of Peace ', 'Chennai ',
                 '55' , '364']

third_option = ['Chennai ', 'Statue of Unity ', 'Delhi ',
                '3,829,400', '366']

fourth_option = ['Nagpur ', 'Statue of Harmony', 'Mumbai',
                 '95', '367']

ans_key = [2,3,3,1,2]

wrong_answer = False

while(wrong_answer != True):
    stage = 0
    print(questions[stage])
    print('1.'+ first_option[stage]+'2.'+ second_option[stage]+
          '3.'+ third_option[stage]+'4.'+ fourth_option[stage])

    answer = int(input("Enter your ans = "))
    if answer == ans_key[stage]:
        stage += 1
        print("Your answer is correct. ")

    else:
        print("Your answer is incorrect, you lose.")
        wrong_answer = True

1 个答案:

答案 0 :(得分:4)

您每次都要重新分配stage,所以请更改:

while(wrong_answer != True):
    stage = 0

收件人:

stage = 0
while(wrong_answer != True):