Question: liberty bell slot machine part 2 finish the missing function and have it produce the correct sample output It cost 5 cents to play and

liberty bell slot machine part 2
finish the missing function and have it produce the correct sample output
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
sample output:
Program 1: Liberty Bell Slot Machine Simulation
--> Part 1: Testing Known Spins
REEL 1 REEL 2 REEL 3 PAYOUT
------------------------
bell bell bell 50
heart heart heart 40
diamond diamond diamond 30
spade spade spade 20
horseshoe horseshoe horseshoe 10
horseshoe horseshoe heart 5
horseshoe diamond horseshoe 5
spade horseshoe horseshoe 5
heart heart horseshoe 0
bell diamond spade 0
--> Part 2: Simulating 500,000 Spins
For every $1 spent, you can expect to win $0.34
missing code/function:
import random
DIAMOND =1
HEART =2
SPADE =3
HORSESHOE =4
LIBERTY_BELL =5
def convert(reel):
if reel == DIAMOND:
return "diamond"
elif reel == HEART:
return "heart"
elif reel == SPADE:
return "spade"
elif reel == HORSESHOE:
return "horseshoe"
elif reel == LIBERTY_BELL:
return "bell"
else:
return "error!"
def test_known_spin(reel1, reel2, reel3):
message = f"{convert(reel1):<10}{convert(reel2):<10}{convert(reel3):<10}{spin_payout(reel1, reel2, reel3):<6d}"
print(message)
def test_known_spins():
print("{:<10}{:<10}{:<10}{:<6}".format("REEL 1", "REEL 2", "REEL 3", "PAYOUT"))
print("{:<10}{:<10}{:<10}{:<6}".format("------","------","------","------"))
test_known_spin(LIBERTY_BELL, LIBERTY_BELL, LIBERTY_BELL)
test_known_spin(HEART, HEART, HEART)
test_known_spin(DIAMOND, DIAMOND, DIAMOND)
test_known_spin(SPADE, SPADE, SPADE)
test_known_spin(HORSESHOE, HORSESHOE, HORSESHOE)
test_known_spin(HORSESHOE, HORSESHOE, HEART)
test_known_spin(HORSESHOE, DIAMOND, HORSESHOE)
test_known_spin(SPADE, HORSESHOE, HORSESHOE)
test_known_spin(HEART, HEART, HORSESHOE)
test_known_spin(LIBERTY_BELL, DIAMOND, SPADE)
def simulate(how_many):
total_winnings =0
for _ in range(how_many):
reel1= random.randint(1,5)
reel2= random.randint(1,5)
reel3= random.randint(1,5)
total_winnings += spin_payout(reel1, reel2, reel3)
print(f"Expected winnings after {how_many} spins: ${total_winnings / how_many:.2f}")
def main():
print("Program 1: Liberty Bell Slot Machine Simulation")
print("Part 1: Testing Known Spins")
test_known_spins()
print("--> Part 2: Simulating 500,000 Spins")
simulate(500000)
if __name__=="__main__":
main()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!