我是一个初学者,我必须创建一个程序来模拟掷骰子10000次,然后告诉用户他们掷了多少次。最困难的是,我只能用两个变量。
import random
count1=0
count2=0
count3=0
count4=0
count5=0
count6=0
dice=random.randint(1,7)
for i in range(10000):
if dice==1:
count1+=1
if dice==2:
count2+=1
if dice==3:
count3+=1
if dice==4:
count4+=1
if dice==5:
count5+=1
if dice==6:
count6+=1
print "You entered "+ str(count1)+ " ones, " + str(count2) + " twos, "+str(count3) + " threes, " +str(count4)+ " fours, " +str(count5)+ " fives, and "+str(count6) +" sixes."
问题是,我不能让程序选择多个随机数,它只会重复相同的数字10000次。另外,如您所见,我不知道如何编写这个只有两个变量的程序,但我认为它可能与列表有关。
目前没有回答
相关问题 更多 >
编程相关推荐