Question: 2 [20 points ] PLEASE WRITE IN PYTHON One-Armed Bandit. In casinos from Monte Carlo to Las Vegas, one of the most common gambling devices
2 [20 points ] PLEASE WRITE IN PYTHON
One-Armed Bandit. In casinos from Monte Carlo to Las Vegas, one of the most common gambling devices is the slot machine - the one-armed bandit. A typical such machine has three horizontally aligned wheels that spin around behind a narrow window. Each wheel is marked with the following symbols: CHERRY, LEMON, ORANGE, PLUM, BELL, and BAR. The window, however, allows you to see only one symbol on each wheel at a time. For example, the window might show the configuration: BELL ORANGE BAR If you put a silver dollar into the slot machine and pull the handle on its side, the wheels spin around and eventually come to a rest in some new configuration. If that configuration matches one among a set of winning patterns printed on the front of the slot machine, you get back some money. If not, youre out a dollar. The following table shows a typical such set of winning patterns along with their associated payoffs: CHERRY pays $2 CHERRY CHERRY pays $5 CHERRY CHERRY CHERRY pays $7 ORANGE ORANGE ORANGE/BAR pays $10 PLUM PLUM PLUM/BAR pays $14 BELL BELL BELL/BAR pays $20 BAR BAR BAR pays $250 The notation BELL/BAR means that either a BELL or a BAR can appear in that position, and a dash means that any symbol at all can appear. Thus, getting a CHERRY in the first position is automatically good for two dollars, no matter what appears on the other wheels. Note that there is never any payoff for the LEMON symbol, even if you happen to line up three of them. Write a program that simulates playing the slot machine. You will do this by writing a program with the functions described below. (10 points) Implement a function called one armed bandit without any parameters. This function should provide the player with an initial stake of $50 and then let her play 3 repeatedly until the money runs out or the player decides to quit (do this with a while loop). During each round, your program should take away a dollar (since each spin of the wheel costs $1). Then spin the wheel and calculate the resulting payoff, if any (via a function spin wheel, described below). Then update the players current money stash appropriately. (10 points) Implement a function called spin wheel without any parameters to simulate the random spinning of the three wheels, print the result of the spins, and determine the resulting payoff. Your function should return the payoff amount. Note: You should assume that each of the six symbols is equally likely on each wheel: i.e. the function spin wheel should mimic three rolls of a die. You can do this by using the randint function from the random module. We will discuss this function in class. (Slot machines in real life are usually biased towards the non-winning combinations to make things profitable for the casino in the long run.) Here is an example of a (lucky) sample run:
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
