我有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