I am trying to make a slot machine but am getting some errors that I cannot fix. It is giving me the wrong amount of coins for each win and a single dollar will not give me any coins (Look at rules below for clarification). I am not sure of any other issues that I could be missing but I believe that it is also only allowing you to win once. Any help is appreciated!
The rules for the slot machine are:
Here is the code:
The rules for the slot machine are:
- One player game starts with 100 coins.
One turn costs 5 coins.
Keep playing until you have no money left, or the player chooses to 'cash out'.
Each go randomly spins the three spinners. Each spinner has 5 symbols: Bell, Cherry, Banana, Dollar, Skull.
3 of any fruit = 50 coins
2 of the same fruit = 10 coins
3 Bells = 1000 coins
2 Bells = 100 coins
3 Dollar = 500 coins
2 Dollar = 50 coins
1 Dollar = 1 coin
If any skull appears on any spinner you may not win any money.
Some examples:
Cherry Cherry Skull = 0 coins
Banana Cherry Banana = 10 coins
Cherry Banana Dollar = 1 coin
Skull Dollar Dollar = 0 coins
Banana Banana Dollar = 11 coins (10 + 1)
Here is the code:
import tkinter as tk
import random
#I added an extra item
#Check line 37
print("Welcome to the Virtual Slot Machine")
global coins
coins = 100
symbols = ["bells", "cherries", "bananas", "dollars", "skull"]
done = False
def sort(lists):
for i in range(len(lists)-1):
for x in range(len(lists)-1-i):
if lists[x] < lists[x + 1]:
lists[x], lists[x + 1] = lists[x + 1], lists[x]
return lists
def open_file():
f = open("highscores.txt","r")
line = f.readlines()
f.close()
list1 = [int(i) for i in line[0].split(",")]
ordered = sort(list1)
return ordered
print("The highscores so far from higherst to smallest are: ")
print(*open_file())
def Match(slot1, slot2, slot3):
if slot1 == slot2 and slot2 == slot3:
return slot1, 1
elif slot1 == slot2:
return slot1, 0
elif slot2 == slot3:
return slot2, 0
elif slot1 == slot3:
return slot3, 0
return None, None
def turn(coins):
coins -= 5
fruits = ["cherries", "bananas"]
slot1 = random.choice(symbols)
slot2 = random.choice(symbols)
slot3 = random.choice(symbols)
slots = [slot1, slot2, slot3]
reward_dict = {"dollars" : [50, 500], "bells": [100, 1000]}
for fruit in fruits:
reward_dict.update({fruit: [10, 50]})
if random.randint(0,10000) == 1:
slot3 = "Gold Bar"
print("You got {} {} {}".format(slot1,slot2,slot3))
if "skull" not in slots:
match, number = Match(slot1, slot2, slot3)
if match != None:
coins += reward_dict[match][number-1]
print("You got {} {}! +{} coins!".format(number+2, match, reward_dict[match][number]))
else:
print("Unlucky, you got a skull, you lose!")
if slot1 == "dollar" or slot2 == "dollar" or slot3 == "dollar":
coins += 1
if slot3 == "Gold Bar":
print("Jackpot! All coins times 10!")
coins = coins*10
return coins
while coins > 0 and done == False:
print("You have {0} coins".format(coins))
play = input("Do you want to play a round? It costs 5 coins? y/n ")
coins_left = coins - 5
if play.lower == "y" and coins_left > 0:
coins = turn(coins)
else:
if coins_left < 0:
print("Sorry, you do not havwe enough money")
print("You ended with {0} coins".format(coins))
else:
print("Ok, thanks for playing")
print("You ended with {0} coins!".format(coins))
done = TrueThanks!
