Lesson 9: Rolling the dice

posted Dec 10, 2019, 8:03 AM by Attila Lengyel   [ updated Dec 12, 2019, 7:59 AM ]
import random as r

print("Let's roll the dice!")
print("I rolled", r.randint(1,6))

rolls = [0,0,0,0,0,0]

for x in range(0,1000):
roll = r.randint(1,6)
rolls[roll-1] = rolls[roll-1] + 1

print(rolls)

total = sum(rolls)

for x in range(0,6):
prob = (rolls[x] / total) * 100
print("The probablity to roll", x + 1, "is", prob, "%")

rolls2 = [0,0,0,0,0,0,0,0,0,0,0,0]
for x in range (0,1000000):
d1 = r.randint(1,6)
d2 = r.randint(1,6)
rolls2[d1+d2-1] = rolls2[d1+d2-1] + 1

for x in range(0,12):
print(x + 1, rolls2[x])
Comments