Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Create a function that simulates a pair of dice being rolled n times
- and returns the number of occurrences of each score -
- this is a more complicated program which will require you to import a Python library.
- If you are not comfortable with this, choose one of the other two challenges
- """
- import random
- min = 1
- max = 6
- list_of_rolls=[]
- def rolldice(n):
- for i in range(n):
- # generate randim dice rolls
- d1 = random.randint(min, max)
- d2 = random.randint(min, max)
- # append roll total to list_of_rolls
- list_of_rolls.append(d1+d2)
- #print(sorted(list_of_rolls)) # used for testing it works
- # printing out the possibilities
- for i in range(2,12+1):
- print(i, list_of_rolls.count(i))
- print(f"No of rolls {len(list_of_rolls)}")
- no_of_rolls = input("Please enter the number of dice rolls > ")
- rolldice(int(no_of_rolls))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement