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)
#3
You could break it down into functions.
I've given an outline below for you to fill in the gaps.

create a constant variable for the rolled dice pattern you would like to match
SNAKE_EYES = (1, 1)
Make a function to roll dice
def roll_dice(num_of_dice):
    ....
    return # returns the rolled dice, possible result (1, 1) if called as roll_dice(2)
Make a function that counts how many rolls to find a match that can be called like this roll_till_match(SNAKE_EYES)
def roll_till_match(match):
   num_of_dice = len(match)
    ....
   # uses roll_dice(num_of_dice) in a loop checking if the result is the same as match
    return # count of rolls till the match
Another function that can call roll_till_match x amount of times that can be called like this roll_till_match_x_times(SNAKE_EYES, 5)
def roll_till_match_x_times(match, x_times):
   ...
   # uses roll_till_match(match) in a loop of x_times
   return # total sum of rolls
The same functions can be used against other matches.
Reply


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

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with dice roll program kraco 4 2,122 Sep-22-2020, 02:06 PM
Last Post: kraco
  simple dice roll Byzas 1 2,357 Mar-21-2019, 02:29 AM
Last Post: ichabod801
Photo roll of the dice kyle007 0 1,733 Mar-11-2019, 01:58 AM
Last Post: kyle007
  unit test roll die saladgg 5 4,202 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,523 Sep-30-2018, 01:19 PM
Last Post: Placebo
  Making a percentile dice roller and dice roller Fixer243 2 3,254 Sep-30-2018, 12:18 PM
Last Post: gruntfutuk
  Random Dice roll program th3h0bb5 1 5,553 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