这是我的代码,为什么它不适合我?它提出了问题,但错过了我创建的if
声明。需要关于随机答案的简单测验帮助
print("What is your name?")
name = input("")
import time
time.sleep(1)
print("Hello", name,(",Welcome to my quiz"))
import time
time.sleep(1)
import random
ques = ['What is 2 times 2?', 'What is 10 times 7?', 'What is 6 times 2?']
print(random.choice(ques))
# Please note that these are nested IF statements
if ques == ('What is 2 times 2?'):
print("What is the answer? ")
ans = input("")
if ans == '4':
print("Correct")
else:
print("Incorrect")
elif ques == ('What is 10 times 7?'):
print("What is the answer? ")
ans = input("")
if ans == '70':
print("Correct")
else:
print("Incorrect")
elif ques == ('What is 6 times 2?'):
print("What is the answer? ")
ans = input("")
if ans == '12':
print("Correct")
else:
print("Incorrect")
import time
time.sleep(1)
import random
ques = ['What is 55 take away 20?', 'What is 60 devided by 2?', 'What is 500 take away 200']
print(random.choice(ques))
if ques == ('What is 55 take away 20?'):
print("What is the answer? ")
ans = input("")
if ans == '35':
print("Correct")
else:
print("Incorrect")
elif ques == ('What is 60 devided by 2?'):
print("What is the answer? ")
ans = input("")
if ans == '30':
print("Correct")
else:
print("Incorrect")
elif ques == ('What is 500 take away 200'):
print("What is the answer? ")
ans = input("")
if ans == '300':
print("Correct")
else:
print("Incorrect")
为什么你多次导入random和time?如果你必须对所有答案进行硬编码,那么对问题做一个'random.choice'有什么意义? – jonrsharpe 2014-10-10 12:22:28
''import time' twice ... – matsjoyce 2014-10-10 12:24:40
不是一个答案,而是:你应该真的试着为所有这些问题做一个函数,比如'def ask_question(num1,num2,operator)',或者如果这太难了,只是'def ask_question(问题,答案)',所以你不必一遍又一遍地重复这些行。 – 2014-10-10 12:31:33