import random elected=[] pp=input('输入该次课班级学号前9位:') while True: chosen1=random.randint(1,4) chosen2=random.randint(1,50) if chosen2<10: chosen2='0'+str(chosen2) # 如果chosen2小于10,前面补0 else: chosen2=str(chosen2) xx=pp+str(chosen1)+chosen2 if xx not in elected: # 判断是否已抽取过该同学 elected.append(xx) print(' 请学号为'+xx+'同学回答问题! ') y=input('回答问题是否正确,正确输入y或Y:') if y=='y' or y=='Y': print('回答正确!!!此轮回答问题结束!') break else: continue # 如果已抽取过该同学,重新抽取 flag=input(' 您是否要继续抽取同学回答问题?如是,请输入y,否则输入n:') if flag!='y' and flag!='Y': print('此轮回答问题结束!') break

Python随机抽取学生回答问题代码优化

原文地址: https://www.cveoy.top/t/topic/nYw8 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录