Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Main Page Problems Solve a Problem H Show Header play-roulette Favorite Language

ID: 3595166 • Letter: M

Question

Main Page Problems Solve a Problem H Show Header play-roulette Favorite Language/Type: Author Python parameters ran Marty Stepp (on 07/08) Write a function namedplay_roulette that generates random numbers to simulate playing a simplified version of the casino game Roulette, as described below. Roulette has a wheel laid flat with colored numbered areas numbered from 0-36. (In some versions, the wheel also has a "00", but not in this problem.) In each round, the wheel is spun and a ball is tossed onto it, landing on one of the numbers. A player bets money on groups of numbers where he/she thinks the ball will land For our game, the player bets that the ball will land on any even number. If the ball lands on an even number, the player wins and if the ball lands on any odd number, the player loses. The number 0 region is special if the ball lands there, the player loses Your function accepts two parameters: an integer for the dollars the player starts with and another integer for the dollars the player will bet each round. At the start, prthree headings of "bet", "spin", and "money" separated by a tab ( ). Then repeatedly use random numbers to simulate spins of the roulette wheel. The player bets the given amount each time, or as close to that amount as the player can afford, until their money reaches 0. If the player doesn't have enough money to bet the given amount, they bet all of their current money. For example, if the bet amount is $5 but the player has only $2, the player bets $2. If the player wins (ball lands on a positive even number), the player receives the amount they bet. If the player loses (ball lands on an odd number or 0), the player loses the amount they bet. After each spin, print the bet amount, the number where the ball landed, and the player's money, separated by a tab (t). Keep going as long as it takes for the money to reach 0. At the end, print the maximum money the player ever had during the session The following log represents the console output from an example call to your function. Because the code uses randomness, each run produces unique output, but your function should exactly match the behavior and output structure shown play_roulette(18, 3)

Explanation / Answer

from random import randint

def play_roulette(money, bet):

print("start with $" + str(money) + " nad bet up to $" + str(bet))

print("bet spin money")

max_money = money

while money > 0:

spin = randint(0, 36)

if spin == 0 or spin % 2 == 1 :

money = money - bet

if money < 0:

money = 0

else:

money = money + bet

if max_money < money:

max_money = money

print("%d %d %d" % (bet, spin, money))

if money < bet:

bet = money

print("max money: $" + str(max_money))

play_roulette(10, 3)

'''

Sample output

start with $10 nad bet up to $3

bet spin money

3 28 13

3 16 16

3 13 13

3 24 16

3 15 13

3 20 16

3 17 13

3 36 16

3 13 13

3 32 16

3 17 13

3 30 16

3 0 13

3 35 10

3 30 13

3 28 16

3 13 13

3 13 10

3 18 13

3 9 10

3 2 13

3 10 16

3 20 19

3 35 16

3 35 13

3 1 10

3 26 13

3 21 10

3 35 7

3 5 4

3 27 1

1 18 2

1 7 1

1 32 2

1 30 3

1 30 4

1 5 3

1 9 2

1 14 3

1 30 4

1 32 5

1 3 4

1 19 3

1 29 2

1 34 3

1 29 2

1 36 3

1 3 2

1 21 1

1 33 0

max money: $19

'''

# copy pastable code link: https://paste.ee/p/rqIiF

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote