Advertisement
timber101

Dice Roller

Dec 12th, 2020
1,005
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. """
  2. Create a function that simulates a pair of dice being rolled n times
  3. and returns the number of occurrences of each score -
  4. this is a more complicated program which will require you to import a Python library.
  5. If you are not comfortable with this, choose one of the other two challenges
  6. """
  7.  
  8. import random
  9. min = 1
  10. max = 6
  11. list_of_rolls=[]
  12.  
  13. def rolldice(n):
  14.     for i in range(n):
  15.         # generate randim dice rolls
  16.         d1 = random.randint(min, max)
  17.         d2 = random.randint(min, max)
  18.         # append roll total to list_of_rolls
  19.         list_of_rolls.append(d1+d2)
  20.  
  21.         #print(sorted(list_of_rolls)) #  used for testing it works
  22.        
  23.         # printing out the possibilities
  24.     for i in range(2,12+1):
  25.         print(i, list_of_rolls.count(i))
  26.    
  27.     print(f"No of rolls {len(list_of_rolls)}")
  28.  
  29.  
  30. no_of_rolls = input("Please enter the number of dice rolls > ")
  31. rolldice(int(no_of_rolls))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement