我有一个作业问题,说明使用 random.choice 函数来模拟骰子的滚动。. 它仍将模拟滚动六面模具 1000 次。我必须输入像 0、1000 这样的列表吗?或者有没有更简单的方法。
import random
def rolldie3():
#6 variables set to 0 as the counter
one = 0
two = 0
three = 0
four = 0
five = 0
six = 0
#use for loop for 1000 times to run
for i in range(1000):
scores = range(0,1000)
#get a random number out of the list
roll = random.choice(scores)
if roll == 1:
one = one + 1
elif roll == 2:
two = two + 1
elif roll == 3:
three = three + 1
elif roll == 4:
four = four + 1
elif roll == 5:
five = five + 1
elif roll == 6:
six = six + 1
#return the variables as a list
return [one,two,three,four,five,six]