Mar-29-2020, 01:21 AM
I am making a slot machine and I am not very experienced at coding. I am struggling to get the coins variable to update at all when I you either gain or lose any. I am unsure of whether it is just the output of it or the actual variable. Here is my 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 = ["bell", "cherry", "banana", "dollar", "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 turn(coins): coins -= 5 fruit = ["cherry", "banana"] slot1 = random.choice(symbols) slot2 = random.choice(symbols) slot3 = random.choice(symbols) if random.randint(0,10000) == 1: slot3 = "Gold Bar" slots = [slot1,slot2,slot3] print("You got {} {} {}".format(slot1,slot2,slot3)) if "skull" not in slots: if (slot1 and slot2 and slot3) == "dollar": print("You got 3 dollars! +500 coins") coins += 500 elif (slot1 and slot2) or (slot1 and slot3) or (slot2 and slot3) == "dollar": print("You got 2 dollars! +50 coins") coins += 50 elif "dollar" in slots: print("You got 1 dollar! + 1 coin") coins += 1 if (slot1 and slot2 and slot3) in fruit: print("You got 3 fruit! +50 coins!") coins += 50 elif ((slot1 and slot2) or (slot1 and slot3) or (slot2 and slot3) in fruit) and (slot1 == slot2) or (slot1 == slot3) or (slot2 == slot3): print("You got 2 of the same fruit! +10 coins") if (slot1 and slot2 and slot3) == "bell": print("You got 3 bells! +1000 coins!") coins += 1000 elif (slot1 and slot2) or (slot1 and slot3) or (slot2 and slot3) == "bell": print("You got 2 bells! +100 coins") else: print("Unlucky, you got a skull, you lose!") if slot3 == "Gold Bar": print("Jackpot! All coins times 10!") coins = coins*10 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 == "y" and coins_left > 0: 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 = True