【发布时间】:2017-12-01 00:32:38
【问题描述】:
def ask_questions():
choice = (random.choice(question))
print(choice)
if choice == 0:
print options[0]
answer0 = raw_input(inputs)
if answer0 == answers[0]:
print("correct")
else:
print("incorrect")
elif choice == 1:
print choice
print options[1]
answer1 = raw_input(inputs)
if answer1 == answers[1]:
print("correct")
else:
print("incorrect")
elif choice == 2:
print choice
print options[2]
answer2 = raw_input(inputs)
if answer2 == answers[2]:
print("correct")
else:
print("incorrect")
elif choice == 3:
print choice
print options[3]
answer3 = raw_input(inputs)
if answer3 == answers[3]:
print("correct")
else:
print("incorrect")
elif choice == 4:
print choice
print options[4]
answer4 = raw_input(inputs)
if answer4 == answers[4]:
print("correct")
else:
print("incorrect")
elif choice == 5:
print choice
print options[5]
answer5 = raw_input(inputs)
if answer5 == answers[5]:
print("correct")
else:
print("incorrect")
def main()
date()
quiz_infos()
welcome()
ask_questions()
main()
我想从列表中随机选择问题
我想知道一种从列表中随机选择问题的方法,如果该问题为 1:打印选项 1 和我的 raw_input(inputs) 同样适用于问题 2 3 4 等 idk 为什么我的代码实际上没有这样做并且只打印问题,所以如果 elif 函数不起作用! 我是 python 新手(编码新手),所以我可能肯定做错了什么, 通过变量[[[[输入=“你认为答案是什么?”]]]] 在此表示感谢! 代码是用python 2.7 idle 编写的
【问题讨论】:
-
我认为您应该仔细查看缩进,然后发布代码的实际输出。您还混合了 python 2 和 3 打印语法。
-
它没有任何问题或错误,它只是不打印列表中的我的选项,也不给我的 if elif 工作
-
一个问题是您的
elif choice == X:语句在您的else:之后,而它们应该在else:语句之前。
标签: python python-3.x python-2.7