Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. #randomly generates a number between 1 and 6
  2. import random
  3.  
  4. #randomly generates two dice rolls
  5. def roll_dice():
  6. first_dice = random.randrange(1,7) #first roll
  7. second_dice = random.randrange(1,7) #second roll
  8. return first_dice,second_dice
  9.  
  10. wins = {}
  11. losses = {}
  12.  
  13. #runs the number of games of craps as defined by the parameter and adding the wins and losses to their respective dictionaries
  14. def play_craps(number_of_games):
  15. dice_sum = sum(roll_dice())
  16. num_rolls_per_game = 0
  17. num_games = number_of_games
  18. games_won_sums = []
  19. games_lost_sums = []
  20.  
  21. #initializes a placeholder "0" for all 21 keys in both wins and losses dictionaries
  22. for i in range(1,22):
  23. wins[i] = 0
  24. losses[i] = 0
  25.  
  26. for j in range(1,number_of_games):
  27. num_games += 1
  28. point = dice_sum
  29.  
  30. for i in range(1,num_rolls_per_game+1):
  31.  
  32. if (dice_sum == 7 or dice_sum == 11) and num_rolls_per_game == 0:
  33. num_rolls_per_game += 1
  34. num_games += 1
  35. games_won_sums.append(dice_sum)
  36.  
  37. elif (dice_sum == 2 or dice_sum == 3 or dice_sum == 12) and num_rolls_per_game == 0:
  38. num_rolls_per_game += 1
  39. num_games += 1
  40. games_lost_sums.append(dice_sum)
  41.  
  42. else:
  43. num_rolls_per_game += 1
  44. if dice_sum == 7:
  45. games_lost_sums.append(dice_sum)
  46. losses[num_rolls_per_game] += 1
  47. if point == dice_sum:
  48. games_won_sums.append(dice_sum)
  49. wins[num_rolls_per_game] += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement