Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Simulating a pair of dice being rolled n times
- #and returns the number of occurence of each score
- from random import randint
- '''
- A function that simulates a pair dice being rolled
- and returns the result
- '''
- def dice_roll():
- dice_1 = randint(1,6)
- dice_2 = randint(1,6)
- return dice_1, dice_2
- '''
- A function that tracks and returns the occurence of
- each score
- '''
- def roll_result(n):
- total_rollResult = []
- i = 0
- while i < n:
- dice1_roll, dice2_roll = dice_roll()
- total_rollResult.append(dice1_roll)
- total_rollResult.append(dice2_roll)
- i += 1
- #Counting the occurence of each score using built-in function
- #count
- one = total_rollResult.count(1)
- two = total_rollResult.count(2)
- three = total_rollResult.count(3)
- four = total_rollResult.count(4)
- five = total_rollResult.count(5)
- six = total_rollResult.count(6)
- return one, two, three, four, five, six
- n = int(input("How many times the dice should be rolled: "))
- one, two, three, four, five, six = roll_result(n)
- print("During rolling a dice " + str(n) + " times")
- print("1 has occured " + str(one) + " times")
- print("2 has occured " + str(two) + " times")
- print("3 has occured " + str(three) + " times")
- print("4 has occured " + str(four) + " times")
- print("5 has occured " + str(five) + " times")
- print("6 has occured " + str(six) + " times")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement