Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #randomly generates a number between 1 and 6
- import random
- #randomly generates two dice rolls
- def roll_dice():
- first_dice = random.randrange(1,7) #first roll
- second_dice = random.randrange(1,7) #second roll
- return first_dice,second_dice
- wins = {}
- losses = {}
- #runs the number of games of craps as defined by the parameter and adding the wins and losses to their respective dictionaries
- def play_craps(number_of_games):
- dice_sum = sum(roll_dice())
- num_rolls_per_game = 0
- num_games = number_of_games
- games_won_sums = []
- games_lost_sums = []
- #initializes a placeholder "0" for all 21 keys in both wins and losses dictionaries
- for i in range(1,22):
- wins[i] = 0
- losses[i] = 0
- for j in range(1,number_of_games):
- num_games += 1
- point = dice_sum
- for i in range(1,num_rolls_per_game+1):
- if (dice_sum == 7 or dice_sum == 11) and num_rolls_per_game == 0:
- num_rolls_per_game += 1
- num_games += 1
- games_won_sums.append(dice_sum)
- elif (dice_sum == 2 or dice_sum == 3 or dice_sum == 12) and num_rolls_per_game == 0:
- num_rolls_per_game += 1
- num_games += 1
- games_lost_sums.append(dice_sum)
- else:
- num_rolls_per_game += 1
- if dice_sum == 7:
- games_lost_sums.append(dice_sum)
- losses[num_rolls_per_game] += 1
- if point == dice_sum:
- games_won_sums.append(dice_sum)
- wins[num_rolls_per_game] += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement