2017-03-27 122 views
0

所以我有明天到期的評估(這是全部完成),並希望增加一些更多的細節。 我將如何: a。這樣做,如果你回答錯誤的問題,你可以重試兩次 b。如果你完全失敗,你會看到答案 我該怎麼做?謝謝 ps。該代碼lloks弱智,我不能讓它在想要打印答案,如果q回答不正確,並給兩個機會

} output = " " score = 0 print('Hello, and welcome to my quiz on Ed Sheeran!') for question_number,question in enumerate(questions): print ("Question",question_number+1) 
print (question) 
for options in questions[question][:-1]: 
    print (options) 
user_choice = input("Make your choice : ") 
if user_choice == questions[question][-1]: 
    print ("Correct!") 
    score += 1 
    print (score) 
    print (output) 

else: 
    print ("Wrong!") 
    print (score) 
    print (output) 

    print(score) 

回答

0

我從您的查詢理解是要用戶輸入選項兩次才移動到下一個問題。 如果用戶在兩次機會中都得到錯誤的回答,您還想顯示答案。

我不知道你的問題和答案是如何存儲的,但你可以使用下面的代碼作爲僞代碼。

下面的代碼應該工作:

print('Hello, and welcome to my quiz on Ed Sheeran!') 
for question_number,question in enumerate(questions): 
    print ("Question",question_number+1) 
    print (question) 
    tmp = 0 
    for options in questions[question][:-1]: 
     print (options) 
    for j in range(2): 
     user_choice = input("Make your choice : ") 
     if user_choice == questions[question][-1]: 
      print ("Correct!") 
      score += 1 
      break 
     else: 
      print ("Wrong!") 
      tmp += 1 
      if tmp == 2: 
       print ('You got it wrong, Correct answer is: ' output) 
    print(score) 
+0

嗨,這個最有效,但IM仍然得到一個錯誤「沒有價值的(輸出)」,這點我是希望能顯示答案。我在這裏放置什麼:output =?。雖然 –

+0

你的'答案'是在'問題'中,還是在其他一些變量? –