我正在制作一个闪存卡程序,以帮助我记忆蟒蛇关键字和术语。但有时它会对我重复答案,这对任何人来说都是显而易见的。
异常1-运行时错误2的另一个名称,运行时错误3的另一个名称-程序的含义。
那么我该如何避免这种重复呢?
while count < 10:
os.system('clear')
wordnum = random.randint(0, len(F1c)-1)
print "What is: ", F1c[wordnum], ""
options = [random.randint(0,len(F2c)-1),random.randint(0,len(F2c)-1),
random.randint(0,len(F2c)-1)]
options[random.randint(0, 2)] = wordnum
print '1 -', F2c[options[0]],
print '2 -', F2c[options[1]],
print '3 -', F2c[options[2]],
answer = input('\nYou choose number ?:')
if options[answer-1] == wordnum:
raw_input('\nCorrect! Hit enter...')
score = score + 1
else:
raw_input('\nWrong! Hit enter...')
count = count + 1
print '\nYour score is:', score发布于 2014-04-10 07:21:35
现在,您什么也不做,以确保第二和第三选择的选项不会与第一冲突。为了做到这一点,您可以在选择第二项之前从列表中删除首选选项,以此类推。
但是,python标准库中有一些函数已经实现了从列表中仔细选择几个项:
answers = random.sample(F2c, 3)或选择索引:
options = random.sample(range(len(F2c)), 3)https://stackoverflow.com/questions/22981033
复制相似问题