Liberty Bell Slot Machine Simulation
Learning Outcomes
Learning Outcomes
- To solve this problem, you need to understand the following Python concepts: data types, functions, selection statements and iteration.
- Charles Fey constructed the first slot machine in 1895. The original machine consisted of three spinning reels containing a total of five symbols: horseshoes, diamonds, spades, hearts and a bell (the Liberty Bell), from which this machine took its name. It cost 5 cents to play and the payouts worked as follows:
- three Liberty Bells: 50 cents
- three hearts: 40 cents
- three diamonds: 30 cents
- three spades: 20 cents
- three horseshoes: 10 cents
- two horseshoes and any other one symbol: 5 cents
- all other combinations: nothing
- To learn more about a subsequent, six-symbol Liberty Bell slot machine, check out this wikipedia article.
- Download Liberty Bell.py, and make sure you fully understand it.
- Write the missing spin_payout function such that it returns the correct payout for any spin.
- Write the missing simulate function such that it simulates the handle of the slot machine being pulled the specified number of times. The simulation may assume that for each reel, the probability of generating any of the five symbols is the same. Once the simulation is finished, the function should print a message stating how much money can be expected to be won for each $1 spent.
- Here is a sample transcript of the program running. Your solution should match the output format exactly. However, because of randomness, the expected winnings per dollar spent might vary each time the program is run.
- 50 points - Each of the ten test spins is calculated correctly in a general fashion. (5 points each - all or nothing.)
- 20 points - The spin_payout function conforms to its comment (5 points), uses meaningful user chosen names (5 points), uses if constructs effectively (5 points) and is as simple as possible (5 points).
- 15 points - The simulate function conforms to its comment (5 points), uses meaningful user chosen names (5 points), and is as simple as possible (5 points).
- 5 points - With the exception of the expected winnings, the output format matches the output format of the transcript exactly. All or nothing.
- 10 points - The expected winning is displayed with two digits to the right of the decimal. All or nothing.