In Python Code. Can you please code. Write a function called play_crapps(num_loa
ID: 3845740 • Letter: I
Question
In Python Code. Can you please code. Write a function called play_crapps(num_loaded) that simulates playing one round of crapps. Use the functions fair_die(), loaded_die, roll(), and make_point() to develop a full simulation model for one round of the game craps depicted in the image above. This function should take as input the number of loaded dice (with the default set to 0). This function should return an integer value of 1 if you win and an integer value of 0 if you lose.
Explanation / Answer
def main(): x = eval(input("how many games will be played?: ")) y = simNGames(x) print(y) def simOneGame(): win = 0 lose = 0 x = rollDice() if x == 2 or x == 3 or x == 12: lose += 1 elif x == 7 or x == 11: win += 1 y = rollDice() while y != 7 or y != x : y = rollDice() if y == x: win += 1 elif y == 7 : lose += 1 if win > lose: return(1) else: return(0) def simNGames(n): wins = 0 loses = 0 x = simOneGame() for i in range(n): if x > 0: wins += 1 else: pass frac = wins / n return float(frac) def rollDice(): return rollDie() + rollDie() def rollDie(): return randrange(1,7)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.