Jun-12-2021, 12:21 PM
I am trying to figure out how many rolls of dice it would take to get a specified number of snake eye rolls. For instance if I want to get snake eyes 5 times in a row and roll until I get it, how many rolls would it take when it's random?
import random streaks = 0 a = random.randint(1, 6) b = random.randint(1, 6) rollnum = 1 while a + b != 2: a = random.randint(1, 6) b = random.randint(1, 6) rollnum +=1 if a + b == 2: streaks += 1 print(f"number of rolls: {rollnum}")So far my code is very basic as I'm a beginner, but what I'd like to do is have a variable that the user can specify (x) and then the dice will roll again and again until it hits snake eyes x times in a row. Then it tells you how many times it had to roll before it hit snake eyes x times in a row.