我有10个骰子,它们的编程都与D1相同。如何在python中设置列表中的值?
D1 = random.randint(1,12)
我再把它们存储在像这样的列表:
roller[DI,D2...]
的人则选择模具,以保持(在while循环),当他要滚动剩余骰子他结束循环。下面的程序成功循环,但是列表中的骰子没有变化。我错过了什么?
while wanted != "11":
print("The dice left in your roll:" , roller)
want = int(input("Select Di by using numbers 0-9."))
di = roller[want]
del roller [want]
keep.append(di)
print("Dice that you have kept:" , keep)
wanted = input("\nType 11 to roll again. Type anything else to select more dice.\n")
wanted = "12"
D1 = random.randint(1,12)
[... more setting ...]
D10 = random.randint(1,12)
然而,通过设置D10骰子D1后,我while循环的下一次迭代不反映辊列表值的变化。为什么是这样?
谢谢。这有很大帮助。能够从骰子中删除数字并仍然使用num = len(骰子)重新掷骰子 dices = [random.randint(1,12)for i in range(0,num)] – 2012-03-29 21:47:17