Advertisement
fnogal

DiceRoll

Nov 26th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. # -------------------------------------------------------------------------
  2. # Programming 102: Think Like a Computer Scientist Raspberry Pi Foundation
  3. # Section 1.7 challenge
  4. # -------------------------------------------------------------------------
  5.  
  6. import random #get the random module
  7.  
  8. # The "flip_coin" function returns a string with either the value "heads" or "tails"
  9. # The value is obtained by first generating a pseudo-ramdom number between 0 and 1
  10. # and assigning all values in the range [0-0.5[ to "heads", and the rest [0.5-1] to "tails"
  11. #
  12. def dice_roll():
  13. return random.randrange(1,7,1)
  14.  
  15. # Main body
  16.  
  17. # Counter for the number of rolls of a certain value - only values 2-12 are needed
  18. totals = [0,0,0,0,0,0,0,0,0,0,0]
  19.  
  20. # Loop a given number of times.
  21. n = int(input("Enter the number of times to roll the die "))
  22. for num in range(n):
  23. tot = dice_roll() + dice_roll()
  24. totals[tot-2] = totals[tot-2] + 1
  25.  
  26. print("Occurrences:")
  27. for num in range(11):
  28. print(num+2,": ",totals[num])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement