import randomelected=pp=input输入该次课班级学号前9位while True chosen1=randomrandint14 chosen2=randomrandint150 if chosen210? else chosen2=strchosen2 xx=pp+strchosen1+chosen2? electe
以下是修改后的代码:
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("\n请学号为"+xx+"同学回答问题!\n") y=input("回答问题是否正确,正确输入y或Y:") if y=="y" or y=="Y": print("回答正确!!!此轮回答问题结束!") break else: continue # 如果已抽取过该同学,重新抽取 flag=input("\n您是否要继续抽取同学回答问题?如是,请输入y,否则输入n:") if flag!="y" and flag!="Y": print("此轮回答问题结束!") brea
原文地址: https://www.cveoy.top/t/topic/eM4V 著作权归作者所有。请勿转载和采集!