【发布时间】:2019-08-22 09:01:22
【问题描述】:
我正在使用列表来跟踪数字,并希望将列表索引与随机数匹配,以便我可以从该索引的值中减去 1。
import random
race_length = int(input("Choose the Length You Would Like You Race To Be
(Between 5 and 15)"))
dice = ["1", "2", "3", "4", "5", "6" ]
cars=[
["1", race_length],
["2", race_length],
["3", race_length],
["4", race_length],
["5", race_length],
["6", race_length],
]
while race_length >0:
print("Press Enter to Roll the Dice")
input()
chosen = int(random.choice(dice))
print(int(chosen))
我该怎么做才能将所选的匹配项与我列表中的数字匹配
【问题讨论】: