请问哪一位大佬可以帮我把其中的问题改成随机出题的形式,万分感谢
本帖最后由 青出于蓝 于 2022-7-29 09:02 编辑while zx <= 14:
if choice == "a":
print("已开启考试模式")
diyi = input("请开启前照灯选择:a.开启大灯 b.远光灯 c.近光灯 d.远,近光灯交替 e.示警灯+示宽灯")
if diyi == "a":
print("很好,你答对了,进入下一题")
zx += 1
else :
print("你答错了,正在退出")
break
dier = input("夜间在没有路灯照明不良条件下行驶选择:a.开启大灯 b.远光灯 c.近光灯 d.远,近光灯交替 e.示警灯+示宽灯")
if dier == "b":
print("很好,进入下一题")
zx += 1
else :
print("哔哔————答错了,正在退出")
break
disan = input("夜间与机动车会车选择:a.开启大灯 b.远光灯 c.近光灯 d.远,近光灯交替 e.示警灯")
if disan == "c":
print("ok,歪瑞谷的")
zx += 1
else :
print("哦,失误了,下次努力")
break
disi = input("夜间直行通过路口选择:a.开启大灯 b.远光灯 c.近光灯 d.远,近光灯交替 e.示警灯")
if disi == "c":
print("oh my god 很好0-0")
zx += 1
else :
print("下次努力")
break
diwu = input("夜间同方向近距离跟车行驶选择:a.开启大灯 b.远光灯 c.近光灯 d.远,近光灯交替 e.示警灯")
if diwu == "c":
print("qwq,加油离胜利不远了")
zx += 1
else :
print("下次努力!!")
break
diliu = input("夜间在照明良好道路上行驶选择:a.开启大灯 b.远光灯 c.近光灯 d.远,近光灯交替 e.示警灯")
if diliu == "c":
print("加油,你是最棒的")
zx += 1
else :
print("下次债见")
break
diqi = input("夜间在有路灯的道路上行驶选择:a.开启大灯 b.远光灯 c.近光灯 d.远,近光灯交替 e.示警灯")
if diqi == "c":
print("go go go!!向前冲")
zx += 1
else :
print("下次债见")
break
diba = input("夜间通过交通信号灯控制的路口选择:a.开启大灯 b.远光灯 c.近光灯 d.远,近光灯交替 e.示警灯")
if diba == "c":
print("只有坚持0才是胜利")
zx += 1
else :
print("下次债见")
break
dijiu = input("夜间通过人行道选择:a.开启大灯 b.远光灯 c.近光灯 d.远,近光灯交替 e.示警灯")
if dijiu == "d":
print("加油,奥里给")
zx += 1
else :
print("下次债见")
break
dishi = input("夜间通过坡路选择:a.开启大灯 b.远光灯 c.近光灯 d.远,近光灯交替 e.示警灯")
if dishi == "d":
print("qwq!")
zx += 1
else :
print("失败是成功之母,没什么")
break
dishiyi = input("夜间通过拱桥选择:a.开启大灯 b.远光灯 c.近光灯 d.远,近光灯交替 e.示警灯")
if dishiyi == "d":
print("叮咚————叮咚,答对了")
zx += 1
else :
print("加油,努力")
break
dishier = input("夜间通过没有交通信号灯控制的路口选择:a.开启大灯 b.远光灯 c.近光灯 d.远,近光灯交替 e.示警灯")
if dishier == "d":
print("咚咚咚,答对了")
zx += 1
else :
print("注意别掉坑!!")
break
dishisan = input("路边临时停车选择:a.开启大灯 b.远光灯 c.近光灯 d.远,近光灯交替 e.示警灯")
if dishisan == "e":
print("欧克,答对了")
zx += 1
else :
print("注意下一次别掉坑!!!")
break
dishisi = input("夜间超越前方车辆选择:a.开启大灯 b.远光灯 c.近光灯 d.远,近光灯交替 e.示警灯")
if dishisi == "d":
print("恭喜你,又答对了一道题")
zx += 1
else :
print("债见")
print("恭喜恭喜,恭喜你答题成功,——————烟花————烟花") import random
question = [
"请开启前照灯选择:a.开启大灯 b.远光灯 c.近光灯 d.远,近光灯交替 e.示警灯+示宽灯",
"夜间在没有路灯照明不良条件下行驶选择:a.开启大灯 b.远光灯 c.近光灯 d.远,近光灯交替 e.示警灯+示宽灯",
"夜间与机动车会车选择:a.开启大灯 b.远光灯 c.近光灯 d.远,近光灯交替 e.示警灯",
"夜间直行通过路口选择:a.开启大灯 b.远光灯 c.近光灯 d.远,近光灯交替 e.示警灯",
"夜间同方向近距离跟车行驶选择:a.开启大灯 b.远光灯 c.近光灯 d.远,近光灯交替 e.示警灯",
"夜间在照明良好道路上行驶选择:a.开启大灯 b.远光灯 c.近光灯 d.远,近光灯交替 e.示警灯",
"夜间在有路灯的道路上行驶选择:a.开启大灯 b.远光灯 c.近光灯 d.远,近光灯交替 e.示警灯",
"夜间通过交通信号灯控制的路口选择:a.开启大灯 b.远光灯 c.近光灯 d.远,近光灯交替 e.示警灯",
"夜间通过人行道选择:a.开启大灯 b.远光灯 c.近光灯 d.远,近光灯交替 e.示警灯",
"夜间通过坡路选择:a.开启大灯 b.远光灯 c.近光灯 d.远,近光灯交替 e.示警灯",
"夜间通过拱桥选择:a.开启大灯 b.远光灯 c.近光灯 d.远,近光灯交替 e.示警灯",
"夜间通过没有交通信号灯控制的路口选择:a.开启大灯 b.远光灯 c.近光灯 d.远,近光灯交替 e.示警灯",
"路边临时停车选择:a.开启大灯 b.远光灯 c.近光灯 d.远,近光灯交替 e.示警灯",
"夜间超越前方车辆选择:a.开启大灯 b.远光灯 c.近光灯 d.远,近光灯交替 e.示警灯"
]
answer = ["a","b","c","c","c","c","c","c","d","d","d","d","e","d"]
zx = 1
choice = "a"
while zx <= 14:
if choice == "a":
print("已开启考试模式")
num = random.randint(0,len(question)-1)
diyi = input(question)
del question
if diyi == answer:
print("很好,你答对了,进入下一题")
del answer
zx += 1
else :
print("你答错了,正在退出")
break
num = random.randint(0,len(question)-1)
dier = input(question)
del question
if dier == answer:
print("很好,进入下一题")
del answer
zx += 1
else :
print("哔哔————答错了,正在退出")
break
num = random.randint(0,len(question)-1)
disan = input(question)
del question
if disan == answer:
print("ok,歪瑞谷的")
del answer
zx += 1
else :
print("哦,失误了,下次努力")
break
num = random.randint(0,len(question)-1)
disi = input(question)
del question
if disi == answer:
print("oh my god 很好0-0")
del answer
zx += 1
else :
print("下次努力")
break
num = random.randint(0,len(question)-1)
diwu = input(question)
del question
if diwu == answer:
print("qwq,加油离胜利不远了")
del answer
zx += 1
else :
print("下次努力!!")
break
num = random.randint(0,len(question)-1)
diliu = input(question)
del question
if diliu == answer:
print("加油,你是最棒的")
del answer
zx += 1
else :
print("下次债见")
break
num = random.randint(0,len(question)-1)
diqi = input(question)
del question
if diqi == answer:
print("go go go!!向前冲")
del answer
zx += 1
else :
print("下次债见")
break
num = random.randint(0,len(question)-1)
diba = input(question)
del question
if diba == answer:
print("只有坚持0才是胜利")
del answer
zx += 1
else :
print("下次债见")
break
num = random.randint(0,len(question)-1)
dijiu = input(question)
del question
if dijiu == answer:
print("加油,奥里给")
del answer
zx += 1
else :
print("下次债见")
break
num = random.randint(0,len(question)-1)
dishi = input(question)
del question
if dishi == answer:
print("qwq!")
del answer
zx += 1
else :
print("失败是成功之母,没什么")
break
num = random.randint(0,len(question)-1)
dishiyi = input(question)
del question
if dishiyi == answer:
print("叮咚————叮咚,答对了")
del answer
zx += 1
else :
print("加油,努力")
break
num = random.randint(0,len(question)-1)
dishier = input(question)
del question
if dishier == answer:
print("咚咚咚,答对了")
del answer
zx += 1
else :
print("注意别掉坑!!")
break
num = random.randint(0,len(question)-1)
dishisan = input(question)
del question
if dishisan == answer:
print("欧克,答对了")
del answer
zx += 1
else :
print("注意下一次别掉坑!!!")
break
num = random.randint(0,len(question)-1)
dishisi = input(question)
del question
if dishisi == answer:
print("恭喜你,又答对了一道题")
del answer
zx += 1
else :
print("债见")
print("恭喜恭喜,恭喜你答题成功,——————烟花————烟花") 虽然已经选了最佳,但是我看了下感觉还是应该再把我写的贴出来,真的没有那么麻烦
如果每道题都需要写好多行代码那么久失去了代码的意义了
相同的重复步骤是可以用函数 循环等等操作的
参考代码:
from random import sample
questions = [
"请开启前照灯选择:a.开启大灯 b.远光灯 c.近光灯 d.远,近光灯交替 e.示警灯+示宽灯",
"夜间在没有路灯照明不良条件下行驶选择:a.开启大灯 b.远光灯 c.近光灯 d.远,近光灯交替 e.示警灯+示宽灯",
"夜间与机动车会车选择:a.开启大灯 b.远光灯 c.近光灯 d.远,近光灯交替 e.示警灯",
"夜间直行通过路口选择:a.开启大灯 b.远光灯 c.近光灯 d.远,近光灯交替 e.示警灯",
"夜间同方向近距离跟车行驶选择:a.开启大灯 b.远光灯 c.近光灯 d.远,近光灯交替 e.示警灯",
"夜间在照明良好道路上行驶选择:a.开启大灯 b.远光灯 c.近光灯 d.远,近光灯交替 e.示警灯",
"夜间在有路灯的道路上行驶选择:a.开启大灯 b.远光灯 c.近光灯 d.远,近光灯交替 e.示警灯",
"夜间通过交通信号灯控制的路口选择:a.开启大灯 b.远光灯 c.近光灯 d.远,近光灯交替 e.示警灯",
"夜间通过人行道选择:a.开启大灯 b.远光灯 c.近光灯 d.远,近光灯交替 e.示警灯",
"夜间通过坡路选择:a.开启大灯 b.远光灯 c.近光灯 d.远,近光灯交替 e.示警灯",
"夜间通过拱桥选择:a.开启大灯 b.远光灯 c.近光灯 d.远,近光灯交替 e.示警灯",
"夜间通过没有交通信号灯控制的路口选择:a.开启大灯 b.远光灯 c.近光灯 d.远,近光灯交替 e.示警灯",
"路边临时停车选择:a.开启大灯 b.远光灯 c.近光灯 d.远,近光灯交替 e.示警灯",
"夜间超越前方车辆选择:a.开启大灯 b.远光灯 c.近光灯 d.远,近光灯交替 e.示警灯"
]
answers = ["a","b","c","c","c","c","c","c","d","d","d","d","e","d"]
dataQA = {i:{'Q':questions, 'A':answers} for i in range(len(questions))}
randQAnum = sample(range(len(questions)), len(questions))
scores = 0
while randQAnum:
QAnum = randQAnum.pop()
QA = dataQA
print('**请听题:')
InA = input('**'+QA['Q'] + '\n--请输入答案:')
if InA.strip().lower() == QA['A']:
scores += 1
print('----叮咚————叮咚,答对了\n')
else:
print('----失败是成功之母,没什么\n')
print('已做完全部题目,你的得分是', scores)
页:
[1]