Advertisement
Guest User

dice_roll

a guest
Mar 18th, 2019
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.43 KB | None | 0 0
  1. #Simulating  a pair of dice being rolled n times
  2. #and returns the number of occurence of each score
  3.  
  4. from random import randint
  5.  
  6. '''
  7.    A function that simulates a pair dice being rolled
  8.    and returns the result
  9. '''
  10. def dice_roll():
  11.     dice_1 = randint(1,6)
  12.     dice_2 = randint(1,6)
  13.     return dice_1, dice_2
  14.  
  15. '''
  16.    A function that tracks and returns the occurence of
  17.    each score
  18. '''
  19. def roll_result(n):
  20.     total_rollResult = []
  21.     i = 0
  22.     while i < n:
  23.         dice1_roll, dice2_roll = dice_roll()
  24.         total_rollResult.append(dice1_roll)
  25.         total_rollResult.append(dice2_roll)
  26.         i += 1
  27.  
  28.     #Counting the occurence of each score using built-in function
  29.     #count  
  30.     one = total_rollResult.count(1)
  31.     two = total_rollResult.count(2)
  32.     three = total_rollResult.count(3)
  33.     four = total_rollResult.count(4)
  34.     five = total_rollResult.count(5)
  35.     six = total_rollResult.count(6)
  36.     return one, two, three, four, five, six
  37.  
  38. n = int(input("How many times the dice should be rolled: "))
  39. one, two, three, four, five, six = roll_result(n)
  40.  
  41. print("During rolling a dice " + str(n) + " times")
  42. print("1 has occured " + str(one) + " times")
  43. print("2 has occured " + str(two) + " times")
  44. print("3 has occured " + str(three) + " times")
  45. print("4 has occured "  + str(four) + " times")      
  46. print("5 has occured " + str(five) + " times")
  47. print("6 has occured " + str(six) + " times")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement