Dice Doubles ๐ฒ
Roll two dice. If they match, that's doubles. How often does that happen? Let's find out the scientific way: roll them 100 times. ๐ฌ
import random
die = random.randint(1, 6) # a random whole number from 1 to 6
randint includes both ends, so you really can get a 1 or a 6.
To do something 100 times you don't need the loop variable at all โ
range(100) just spins round 100 times:
for roll in range(100):
print("rolling!")
Your mission
- Roll two dice, 100 times
- Count how many rolls came out as doubles โ store it in a variable
called
doubles - Print the result
Run it a few times. The number changes! What do you think it should be, out of 100? ๐ค
Your code
Press โถ Run to see what your code does!