For an introductory course in Python, I have the task of doing a simulation for eolling dice
You want all your cubes (5 in total) to get the value six, and calculate how many discounts are required for a person to get all the poles. I need a loop that simulates this problem 100,000 times, and then I need to divide the total number of samples by 100,000 to get the result. I know that the final result should be about 13, but I donβt understand this, and I donβt know why.
I know that something is wrong with my approach to this problem, but what?
import random
count1=0
count2=0
count3=0
count4=0
count5=0
loopcounter = 0
for loopcouter in range (1,100000):
dice1=int( random.random()*6)+1
if dice1 != 6:
while dice1 != 6:
dice1=int( random.random()*6)+1
count1 = count1+1
else:
count1 = 1
dice2=int( random.random()*6)+1
if dice2 != 6:
while dice2 != 6:
dice2=int( random.random()*6)+1
count2 = count2+1
else:
count2 = 1
dice3=int( random.random()*6)+1
if dice3 != 6:
while dice3 != 6:
dice3=int( random.random()*6)+1
count3 = count3+1
else:
count3 = 1
dice4=int( random.random()*6)+1
if dice4 != 6:
while dice4 != 6:
dice4=int( random.random()*6)+1
count4 = count4+1
else:
count4 = 1
dice5=int( random.random()*6)+1
if dice5 != 6:
while dice5 != 6:
dice5=int( random.random()*6)+1
count5 = count5+1
else:
count5 = 1
print (count1)
print (count2)
print (count3)
print (count4)
print (count5)
allcount = count1+count2+count3+count4+count5
averagecount = int(allcount / 100000)
print ("the total number of throws is",allcount)
print ("the average number of throws is",averagecount)
So, if anyone can tell me what I'm doing wrong, that would be great!