lundi 26 octobre 2015

rolling 2 6 sided die repeatedly until a 1's are rolled

repeats 100 times, keeps track of number of rolls. prints out average number of rolls that it took to get the 1 on both dice. use nested loops. outer loop repeats 100 times. inner loop continues rolling until you get 1's on both die. print out trial number. prints out result of each roll. stops when both dice are 1 add total number of rolls to running total. import random dice1, dice2 = " ", " " roll = " "

for roll in range(1, 101):
    roll = 0
    dice1 = random.randint(1, 6)
    dice2 = random.randint(1, 6)
    print(dice1, ",", dice2)
    while dice1 == 1 and dice2 == 1:
         break

this doesn't stop when 2 1's a rolled and i need help accumulating the roll number and trial number




Aucun commentaire:

Enregistrer un commentaire