1. fInd the average win and lose rate of the crabs game 2. Find the Mean, Median, and mode of how long a player takes until he wins and loses a game.Basically find out how long each game lasts. With mean, median, and mode. This code is for python and its for the craps game. Below is the code I have so far. import random import sys import pandas as pd def roll_dice(): die1 = random.randrange(1, 7) die2 = random.randrange(1, 7) return (die1, die2) def display_dice(dice): die1, die2 = dice print(f'Player rolled {die1} + {die2} = {sum(dice)}') # List that stores number of wins on every roll winList = [] # List that stores number of losses on every roll lossList = [] # List that stores label indexes of horizontal bar plot ylabel = [] # 1 # number of games of craps n = int(input("Enter number of games: ")) # Iterating 13 times # Because it is mentioned in the question that plot should have 13 # horizontal bars for wins, and 13 horizontal bars for losses. for roll in range(13): ylabel.append('Roll ' + str(roll + 1)) # variables that keep track of wins and losses on every roll # for the given number of games of craps wins = losses = 0 for i in range(n): die_values = roll_dice() display_dice(die_values) sum_of_dice = sum(die_values) if sum_of_dice in (7, 11): game_status = 'WON' wins += 1 elif sum_of_dice in (2, 3, 12): game_status = 'LOST' losses += 1 else: game_status = 'CONTINUE' my_point = sum_of_dice print('Point is', my_point) while game_status == 'CONTINUE': die_values = roll_dice() display_dice(die_values) sum_of_dice = sum(die_values) if sum_of_dice == my_point: game_status = 'WON' wins += 1 elif sum_of_dice == 7: game_status = 'LOST' losses += 1 if game_status == 'WON': print('Player wins') else: print('Player loses') winList.append(wins) lossList.append(losses)
1. fInd the average win and lose rate of the crabs game
2. Find the Mean, Median, and mode of how long a player takes until he wins and loses a game.Basically find out how long each game lasts. With mean, median, and mode.
This code is for python and its for the craps game. Below is the code I have so far.
import random
import sys
import pandas as pd
def roll_dice():
die1 = random.randrange(1, 7)
die2 = random.randrange(1, 7)
return (die1, die2)
def display_dice(dice):
die1, die2 = dice
print(f'Player rolled {die1} + {die2} = {sum(dice)}')
# List that stores number of wins on every roll
winList = []
# List that stores number of losses on every roll
lossList = []
# List that stores label indexes of horizontal bar plot
ylabel = []
# 1
# number of games of craps
n = int(input("Enter number of games: "))
# Iterating 13 times
# Because it is mentioned in the question that plot should have 13
# horizontal bars for wins, and 13 horizontal bars for losses.
for roll in range(13):
ylabel.append('Roll ' + str(roll + 1))
# variables that keep track of wins and losses on every roll
# for the given number of games of craps
wins = losses = 0
for i in range(n):
die_values = roll_dice()
display_dice(die_values)
sum_of_dice = sum(die_values)
if sum_of_dice in (7, 11):
game_status = 'WON'
wins += 1
elif sum_of_dice in (2, 3, 12):
game_status = 'LOST'
losses += 1
else:
game_status = 'CONTINUE'
my_point = sum_of_dice
print('Point is', my_point)
while game_status == 'CONTINUE':
die_values = roll_dice()
display_dice(die_values)
sum_of_dice = sum(die_values)
if sum_of_dice == my_point:
game_status = 'WON'
wins += 1
elif sum_of_dice == 7:
game_status = 'LOST'
losses += 1
if game_status == 'WON':
print('Player wins')
else:
print('Player loses')
winList.append(wins)
lossList.append(losses)
In this question, it is asked to provide the python code for a problem statement.
The statement asks to find the average win and loss percentage of craps game
It also asks to find the mean, median, and mode for the number of rolls of dice required for win/loss.
Step by step
Solved in 2 steps with 2 images