I can not get this python slot machine to function. Also, how do add a counter to track and display the number of times the user plays, and an accumulator to track and display the total amount of money won. The outer loop with a sentinel value which prompts whether the user wishes to continue playing is not working.
import random
words = ["Cherries", "Oranges", "Plums","Melons", "Bells"]
rand1 = random.randint(0,4)
rand2 = random.randint(0,4)
rand3 = random.randint(0,4)
word1 = words[rand1]
word2 = words[rand2]
word3 = words[rand3]
def random_calculate (calculate):
print(word1, " ", word2, " ", word3)
if (rand1 == rand2 or rand2 == rand3 or rand1 == rand3):
if (rand1 == rand2 and rand2 == rand3):
if(ranrand1=="Bells"):
win=50
else:
win = 10
else:
win = 5
def display_menue():
print ("Welcome to the Slot Machine!")
print (" Match 2 of any kind to win $5")
print (" Match 3 of any fruit to win $10")
print (" Match 3 BELLS to win $50!")
def main():
display_menue()
calculate = random_calculate
choice = "y"
while choice.lower() == "y":
choice = input("Do you want to play? (y or n): ")
print("OK, pull the lever!")
print()
print("You have won $" + str(win))
if __name__ == "__main__":
main()