Question

In: Computer Science

A slot machine is a gambling device which allows a user to insert money and pull a lever (or push a button) and displays a set of random images.

A slot machine is a gambling device which allows a user to insert money and pull a lever (or push a button) and displays a set of random images. Design a Python program which simulates a "free" slot machine which displays a random combination of 3 of the following items (as text): Cherries, Oranges, Plums, Melons, and Bells 

  • If none of the items match, the user wins nothing. 

  • If only two of the items match, the user wins $5 

  • If all three items match, the user wins $10 

  • If the user matches 3 Bells, the user wins $50

Solutions

Expert Solution

https://onlinegdb.com/ryqZ6pFR4

import random # To generate random numbers


# Now, we define a list to store the words
words = ["Cherries", "Oranges", "Plums", "Bells", "Melons", "Bars"]

# Generate the 3 random Numbers
rand1 = random.randint(0,5)
rand2 = random.randint(0,5)
rand3 = random.randint(0,5)

# Get the 3 words
word1 = words[rand1]
word2 = words[rand2]
word3 = words[rand3]

# Output the words (formatted to look good)
print(word1, " ", word2, " ", word3)

if (rand1 == rand2 or rand2 == rand3 or rand1 == rand3):
# If atleast two of the numbers generated are EQUAL
if (rand1 == rand2 and rand2 == rand3):
if(rand1=="Bells"):
win=50;
# If all 3 generated numbers are EQUAL
else:
win = 10
# Print that user has won jackpot
else:
# If only two of the numbers generated are EQUAL
win = 5
else:
# If none of the numbers generated are equal
win = 0

# Print the amount user has won
print("You have won $" + str(win))


Related Solutions

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT