Python Forum
Dice Roll (Find out how many rolls until specified streak)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dice Roll (Find out how many rolls until specified streak)
#1
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.
Reply


Messages In This Thread
Dice Roll (Find out how many rolls until specified streak) - by DustinKlent - Jun-12-2021, 12:21 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with dice roll program kraco 4 2,112 Sep-22-2020, 02:06 PM
Last Post: kraco
  simple dice roll Byzas 1 2,355 Mar-21-2019, 02:29 AM
Last Post: ichabod801
Photo roll of the dice kyle007 0 1,731 Mar-11-2019, 01:58 AM
Last Post: kyle007
  unit test roll die saladgg 5 4,186 Nov-06-2018, 11:39 PM
Last Post: stullis
  Issue with my 'roll the dice simulation'-exercise (cannot break out of the loop) Placebo 2 3,517 Sep-30-2018, 01:19 PM
Last Post: Placebo
  Making a percentile dice roller and dice roller Fixer243 2 3,247 Sep-30-2018, 12:18 PM
Last Post: gruntfutuk
  Random Dice roll program th3h0bb5 1 5,545 Oct-18-2016, 09:25 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020