是否可以使列表中的項目一次顯示一個項目,但是在程序顯示下一個項目之前它必須等待用戶輸入?如何使列表中的項目顯示,並且來自用戶的輸入
這裏是我的代碼:
import os
correct=0
incorrect=0
missed_questions=[]
incorrect_questions=[]
def question1(question_name,question):
print(question_name)
print(question)
answer=int(input())
if answer == 4:
os.system('cls')
global correct
correct=correct+1
elif answer != 4:
global incorrect
incorrect=incorrect+1
global missed_questions
missed_questions.append(question_name)
global incorrect_questions
incorrect_questions.append(question)
def question2(question_name,question):
print(question_name)
print(question)
answer=int(input())
if answer == 1:
os.system('cls')
global correct
correct=correct+1
elif answer != 1:
global incorrect
incorrect=incorrect+1
global missed_questions
missed_questions.append(question_name)
global incorrect_questions
incorrect_questions.append(question)
def question3(question_name,question):
print(question_name)
print(question)
answer=int(input())
if answer == 2:
os.system('cls')
global correct
correct=correct+1
elif answer != 2:
global incorrect
incorrect=incorrect+1
global missed_questions
missed_questions.append(question_name)
global incorrect_questions
incorrect_questions.append(question)
def question4(question_name,question):
print(question_name)
print(question)
answer=int(input())
if answer == 3:
os.system('cls')
global correct
correct=correct+1
elif answer != 3:
global incorrect
incorrect=incorrect+1
global missed_questions
missed_questions.append(question_name)
global incorrect_questions
incorrect_questions.append(question)
def question5(question_name,question):
print(question_name)
print(question)
answer=int(input())
if answer == 3:
os.system('cls')
global correct
correct=correct+1
elif answer != 3:
global incorrect
incorrect=incorrect+1
global missed_questions
missed_questions.append(question_name)
global incorrect_questions
incorrect_questions.append(question)
def question6(question_name,question):
print(question_name)
print(question)
answer=int(input())
if answer == 4:
os.system('cls')
global correct
correct=correct+1
elif answer != 4:
global incorrect
incorrect=incorrect+1
global missed_questions
missed_questions.append(question_name)
global incorrect_questions
incorrect_questions.append(question)
def question7(question_name,question):
print(question_name)
print(question)
answer=int(input())
if answer == 3:
os.system('cls')
global correct
correct=correct+1
elif answer != 3:
global incorrect
incorrect=incorrect+1
global missed_questions
missed_questions.append(question_name)
global incorrect_questions
incorrect_questions.append(question)
def question8(question_name,question):
print(question_name)
print(question)
answer=int(input())
if answer == 1:
os.system('cls')
global correct
correct=correct+1
elif answer != 1:
global incorrect
incorrect=incorrect+1
global missed_questions
missed_questions.append(question_name)
global incorrect_questions
incorrect_questions.append(question)
def question9(question_name,question):
print(question_name)
print(question)
answer=int(input())
if answer == 1:
os.system('cls')
global correct
correct=correct+1
elif answer != 1:
global incorrect
incorrect=incorrect+1
global missed_questions
missed_questions.append(question_name)
global incorrect_questions
incorrect_questions.append(question)
def question10(question_name,question):
print(question_name)
print(question)
answer=int(input())
if answer == 1:
os.system('cls')
global correct
correct=correct+1
elif answer != 1:
global incorrect
incorrect=incorrect+1
global missed_questions
missed_questions.append(question_name)
global incorrect_questions
incorrect_questions.append(question)
def quiz():
question1('Question 1:', '123 - 39 = ? \n 1. 64 \n 2. 44 \n 3. 74 \n 4. 84')
question2('Question 2:' ,'123 + 39 = ? \n \n 1. 162 \n 2. 166 \n 3. 62 \n 4. 66')
question3('Question 3:' ,'123 * 9 = ? \n 1. 1007 \n 2. 1107 \n 3. 1106 \n 4. 1116')
question4('Question 4:' ,'135/15 = ? \n 1. 8 \n 2. 8.5 \n 3. 9 \n 4. 9.5')
question5('Question 5:' ,'12 * (12/2) = ? \n 1. 144 \n 2. 6 \n 3. 72 \n 4. 36')
question6('Question 6:' ,'130/2 + 8 = ? \n 1. 13 \n 2. 14 \n 3. 61 \n 4. 84')
question7('Question 7:' ,'10 + 12 + 13 * 6/2 = ? \n 1. 105 \n 2. 44 \n 3. 61 \n 4. 84')
question8('Question 8:' ,'10 + 12 + 13 * 6)/2 = ? \n 1. 50 \n 2. 44 \n 3. 61 \n 4. 84')
question9('Question 9:' ,'8 (12 + 6/3 * 2) - 1 = ? \n 1. 127 \n 2. 109 \n 3. 95 \n 4. 135')
question10('Question 10:' ,'1/1 * 1 - 1 + 1 = ? \n 1. 1 \n 2. -1 \n 3. 0 \n 4. -2')
def tryagain():
while True:
answer = input('Do you want to try again?: Press Y for yes and N for no ')
if answer.lower().startswith("y"):
os.system('cls')
print('****** Welceome to the Online Maths Test ********')
print()
print()
print()
print()
print()
print()
print()
os.system("PAUSE")
print(quiz())
elif answer.lower().startswith("n"):
exit()
def re_take():
re_take= input('Do you want to re-take the incorrect quesations? Press Y for y and N for No')
if take.lower().startswith("y"):
print(incorrect_questions)
else:
print(tryagain())
print('****** Welceome to the Online Maths Test ********')
print()
print()
print()
print()
print()
print()
print()
os.system("PAUSE")
quiz()
for q in missed_questions:
print('Incorrect questions were: ', q)
print('')
print('')
print('')
re_take()
我試圖在重走funcation列表。
是的,這是可能的 – miradulo
當然是這樣,你有沒有嘗試過任何東西? –
我累了,但我不能找到正確的編碼。如果你能以一個很棒的例子展示我。 – Jamal