Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -------------------------------------------------------------------------
- # Programming 102: Think Like a Computer Scientist Raspberry Pi Foundation
- # Section 1.7 challenge
- # -------------------------------------------------------------------------
- import random #get the random module
- # The "flip_coin" function returns a string with either the value "heads" or "tails"
- # The value is obtained by first generating a pseudo-ramdom number between 0 and 1
- # and assigning all values in the range [0-0.5[ to "heads", and the rest [0.5-1] to "tails"
- #
- def dice_roll():
- return random.randrange(1,7,1)
- # Main body
- # Counter for the number of rolls of a certain value - only values 2-12 are needed
- totals = [0,0,0,0,0,0,0,0,0,0,0]
- # Loop a given number of times.
- n = int(input("Enter the number of times to roll the die "))
- for num in range(n):
- tot = dice_roll() + dice_roll()
- totals[tot-2] = totals[tot-2] + 1
- print("Occurrences:")
- for num in range(11):
- print(num+2,": ",totals[num])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement