226k views
2 votes
A slot machine is a gambling device that the user inserts money into and then pulls a lever (or presses a button). The slot machine then displays a set of random images. If two or more of the images match, the user wins an amount of money that the slot machine dispenses back to the user. Design a program that simulates a slot machine. When the program runs, it should do the following: Ask the user to enter the amount of money he or she wants to insert into the slot machine. Instead of displaying images, the program will randomly select a word from the following list: Cherries, Oranges, Plums, Bells, Melons, Bars The program will select and display a word from this list three times. If none of the randomly selected words match, the program will inform the user that he or she has won $0. If two of the words match, the program will inform the user he or she has won two times the amount entered. If three of the words match, the program will inform the user that he or she has won three times the amount entered. The program will ask whether the user wants to play again. If so, these steps are repeated. If not, the program displays the total amount of money entered into the slot machine and the total amount won.

User Detay
by
4.0k points

1 Answer

11 votes

Answer:

import random

is_cont = 'y'

amount = float(input("Enter amount: "))

total = 0.0

slot = ['Cherries', 'Oranges', 'Plums', 'Bells', 'Melons', 'Bars']

while is_cont == 'y':

hold = []

for i in range(3):

ent = random.choice(slot)

print(ent)

hold.append(ent)

if hold.count(hold[0]) == 3 or hold.count(hold[1]) == 3 or hold.count(hold[2]) == 3:

print(f"{3 * amount}")

total += 3 * amount

elif hold.count(hold[0]) == 2 or hold.count(hold[1]) == 2 or hold.count(hold[2]) == 2:

print(f"{2 * amount}")

total += 2 * amount

else:

print("$ 0")

is_cont = input("Try again? y/ n: ")

Step-by-step explanation:

The python program is in a constant loop so long as the 'is_cont' variable has a value of 'y'. The program implements a slot machine as it gets an amount of money from the player and randomly selects an item from the slot list variable three times.

If all three selections match, the player gets three times the amount paid and if two items match, then the player gets twice the pay but gets nothing if all three items are different.

User Rikki Gibson
by
4.3k points