Dictionary not being called correctly

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RX400
    New Member
    • Mar 2020
    • 1

    Dictionary not being called correctly

    I have a slot machine program I am trying to make but it is not working very well. I believe the issue is I am calling the wrong thing from a dictionary. The correct amount of coins are not given and I am unsure why. The specifications for it are:

    One player game starts with 100 coins.
    One turn costs 5 coins.
    Keeps 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
    A gold bar means all money is multiplied by 10
    If any skulls appear on any spinner you may not win any money

    Here is the code:

    Code:
    import tkinter as tk
    import random
    
    
    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 == "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 = True
    Thank You!
    Last edited by RX400; Mar 29 '20, 03:21 PM. Reason: Add code tags
Working...