473,387 Members | 1,650 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Dictionary not being called correctly

1
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:

Expand|Select|Wrap|Line Numbers
  1. import tkinter as tk
  2. import random
  3.  
  4.  
  5. print("Welcome to the Virtual Slot Machine")
  6. global coins
  7. coins = 100
  8. symbols = ["bells", "cherries", "bananas", "dollars", "skull"]
  9. done = False
  10.  
  11. def sort(lists):
  12.   for i in range(len(lists)-1):
  13.     for x in range(len(lists)-1-i):
  14.       if lists[x] < lists[x + 1]:
  15.         lists[x], lists[x + 1] = lists[x + 1], lists[x]
  16.  
  17.   return lists
  18.  
  19. def open_file():
  20.   f = open("highscores.txt","r")
  21.   line = f.readlines()
  22.   f.close()
  23.   list1 = [int(i) for i in line[0].split(",")]
  24.   ordered = sort(list1)
  25.   return ordered
  26.  
  27. print("The highscores so far from higherst to smallest are: ")
  28. print(*open_file())
  29.  
  30. def Match(slot1, slot2, slot3):
  31.   if slot1 == slot2 and slot2 == slot3:
  32.     return slot1, 1
  33.   elif slot1 == slot2:
  34.     return slot1, 0
  35.   elif slot2 == slot3:
  36.     return slot2, 0
  37.   elif slot1 == slot3:
  38.     return slot3, 0
  39.   return None, None
  40.  
  41. def turn(coins):
  42.   coins -= 5
  43.   fruits = ["cherries", "bananas"]
  44.   slot1 = random.choice(symbols)
  45.   slot2 = random.choice(symbols)
  46.   slot3 = random.choice(symbols)
  47.   slots = [slot1, slot2, slot3]
  48.   reward_dict = {"dollars" : [50, 500], "bells": [100, 1000]}
  49.   for fruit in fruits:
  50.       reward_dict.update({fruit: [10, 50]})
  51.  
  52.   if random.randint(0,10000) == 1:
  53.     slot3 = "Gold Bar"
  54.  
  55.   print("You got {} {} {}".format(slot1,slot2,slot3))
  56.  
  57.   if "skull" not in slots:
  58.     match, number = Match(slot1, slot2, slot3)
  59.     if match != None:
  60.       coins += reward_dict[match][number-1]
  61.       print("You got {} {}! +{} coins!".format(number+2, match, reward_dict[match][number]))
  62.  
  63.   else:
  64.     print("Unlucky, you got a skull, you lose!")
  65.  
  66.   if slot1 == "dollar" or slot2 == "dollar" or slot3 == "dollar":
  67.     coins += 1
  68.  
  69.   if slot3 == "Gold Bar":
  70.     print("Jackpot! All coins times 10!")
  71.     coins = coins*10
  72.   return coins
  73.  
  74. while coins > 0 and done == False:
  75.   print("You have {0} coins".format(coins))
  76.   play = input("Do you want to play a round? It costs 5 coins? y/n ")
  77.   coins_left = coins - 5
  78.   if play == "y" and coins_left > 0:
  79.     coins = turn(coins)
  80.   else:
  81.     if coins_left < 0:
  82.       print("Sorry, you do not havwe enough money")
  83.       print("You ended with {0} coins".format(coins))
  84.     else:
  85.       print("Ok, thanks for playing")
  86.       print("You ended with {0} coins!".format(coins))
  87.       done = True
  88.  
Thank You!
Mar 29 '20 #1
0 1252

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: none | last post by:
or is it just me? I am having a problem with using a dictionary as an attribute of a class. This happens in python 1.5.2 and 2.2.2 which I am accessing through pythonwin builds 150 and 148...
7
by: Rolf Kemper | last post by:
Dear All, somehow I remember that such or similar question was discussed already somewhere. But I can't find it anymore. I have a template calling itself. As long it goes deeper into the...
4
by: Noah | last post by:
I have a dictionary that I would like to expand to satisfy a function's agument list. I can used the ** syntax to pass a dictionary, but this only works if each key in the dictionary matches an...
12
by: Elhanan | last post by:
hi.. i wanted to build a Dictionary Classs that will load my own class called letter, i understood that i implement the IEquatable interface's equles method that then the dictionary would use...
0
by: Nebelung | last post by:
Hi! I've written a custom ExpandableObjectConverter in which I have overridden GetPropertiesSupported and GetProperties (and some more). By setting breakpoints in all methods I have found out...
0
by: Nebelung | last post by:
Hi! I've written a custom ExpandableObjectConverter in which I have overridden GetPropertiesSupported and GetProperties (and some more). The class to which this TypeConverter is applied has all...
0
by: Nebelung | last post by:
In a custom ExpandableObjectConverter I have overridden GetPropertiesSupported (always returns true) and GetProperties. The class to which this TypeConverter is applied has only public properties...
14
by: vatamane | last post by:
This has been bothering me for a while. Just want to find out if it just me or perhaps others have thought of this too: Why shouldn't the keyset of a dictionary be represented as a set instead of a...
7
by: Ben | last post by:
Hello... I have a dictionary, where each value is a seperate instance of the same class: self.mop_list=record(self.mops) In my case I know that record_number takes the values 0,3,and 7...
3
by: kim.nolsoee | last post by:
Hi I want to use the Dictionary Classs that will load my own class called KeyClass used as TKey. Here is the code: public class Dictionary { public static void Main()
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.