Advertisement
elena_gancedo

Exercice2.2_102

Jul 31st, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1. # Function that simulates a pair of dice being rolled n times and
  2. # returns the number of occurrences of each score.
  3. #Possible results:
  4. #(1,1) (1,2) (1,3) (1,4) (1,5) (1,6)
  5. #(2,1) (2,2) (2,3) (2,4) (2,5) (2,6)
  6. #(3,1) (3,2) (3,3) (3,4) (3,5) (3,6)
  7. #(4,1) (4,2) (4,3) (4,4) (4,5) (4,6)
  8. #(5,1) (5,2) (5,3) (5,4) (5,5) (5,6)
  9. #(6,1) (6,2) (6,3) (6,4) (6,5) (6,6)
  10. import random
  11. def throw_dice(game):
  12.     if game == "yes":
  13.         n1 = random.randint(1,6)
  14.         n2 = random.randint(1,6)
  15.         print("The result of dice one is " + str(n1) + " and the dice two is " +str(n2))
  16.         print("The sum of the two dice thrown is " + str(n1+n2))
  17.     return
  18. # main
  19. print("Let's roll the dice!")  
  20. # loop  
  21. finished = False
  22. while finished == False:
  23.     game = input("Do you want to throw the dice? yes/no: ")
  24.     if game == "yes":
  25.         throw_dice(game)
  26.     else:
  27.         print("The answer has been... " + game + " , then bye.")
  28.         break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement