I'm a beginner in Python, 1-2 months experience. Please assess my code. I used a dictionary to store cases. The cases_data is stored in another file. Is the structuring right? My code seems to have a lot of whitespace, how can I restructure it for readability? The code runs successfully as intended, but is the code suited for maintainability (adding new features)? Am I following the Python standard? Is this satisfactory for industrial standard? I did this project for leisure.
cases = {
"wildfire" : {
"blue" : ['Tec-9 | Jambiya', 'USP-S | Lead Conduit', 'SSG 08 | Necropos', 'Dual Berettas | Cartel', 'MAC-10 | Lapis Gator', 'PP-Bizon | Photic Zone'],
"purple" : ['MAG-7 | Praetorian', 'FAMAS | Valence', 'Five-SeveN | Triumvirate', 'Glock-18 | Royal Legion'],
"pink" : ['Desert Eagle | Kumicho Dragon', 'Nova | Hyper Beast', 'AWP | Elite Build'],
"red" : ['AK-47 | Fuel Injector', 'M4A4 | The Battlestar'],
},
"chroma 2" : {
'blue' : ['AK-47 | Elite Build', 'MP7 | Armor Core', 'Desert Eagle | Bronze Deco', 'P250 | Valence', 'Sawed-Off | Origami'],
'purple' : ['AWP | Worm God', 'MAG-7 | Heat', 'CZ75-Auto | Pole Position', 'UMP-45 | Grand Prix'],
'pink' : ['Five-SeveN | Monkey Business', 'Galil AR | Eco', 'FAMAS | Dijinn'],
'red' : ['M4A1-S | Hyper Beast', 'MAC-10 | Neon Rider'],
},
}
import random
from cases_data import *
stattrrak=['StatTrrak',]
knives=['Karambit', 'Flip knife', 'M9 Bayonet', 'Bayonet', 'Flachion', 'Shaddow Daggers', 'Bowie Knife']
wear = ['battle scarred', 'well worn', 'field tested', 'minimal wear', 'factory new']
print ("Hello! Welcome to CS GO case lottery!")
print ("Available cases: Wildfire and Chroma 2")
print ("Winning a purple skin gives you 1 additional key!")
print ("Winning a pink skin gives you 3 additional keys!")
print ("Winning a red skin gives you 7 additional keys!")
print ("Winning a knife gives you 15 additional keys!")
global caseKeys
caseKeys = 1
def skin_wear():
x = random.choice(wear)
return x
def case_run():
global caseKeys
chance1 = random.randint(1, 100)
while caseKeys >0:
resp = input("Which case would you like to open? ")
for i in cases:
if resp.lower() == i:
caseKeys -= 1
colours = list(cases[i].items())
#print ("Colours: %s" % colours)
chance = random.randint(1, 100)
for x, y in enumerate([25, 10, 5, 2]):
if chance >=y:
trakChance= random.randint(1, 100)
skinRarity = colours[x][0]
skin = random.choice(colours[x][1])
if trakChance <= 35:
print ("You've won a %s (%s) (%s skin) (StatTrrak)" % (skin, skin_wear(), skinRarity))
print ("With a chance of %s" % chance)
else:
print ("You've won a %s (%s) (%s skin)" % (skin, skin_wear(), skinRarity))
print ("With a chance of %s" % chance)
if skinRarity == 'purple':
caseKeys += 1
elif skinRarity == 'pink':
caseKeys += 3
elif skinRarity == 'red':
caseKeys += 7
print ("Keys left: %s" % caseKeys)
break
elif chance == 1:
print ("You've won a %s, Congratulations!" % random.choice(knives))
print ("With a chance of %s" % chance)
print ("Nice! 15 more keys!")
caseKeys += 15
print ("Keys left: %s" % caseKeys)
break
break
if resp.lower() != i:
print ("Please see list for cases")
else:
print ("You've run out of keys")
if caseKeys == 0:
resp2=input("Would you like to try again? ")
if resp2.lower() == 'yes' or 'y':
resp3=int(input("How many keys? "))
caseKeys = resp3
case_run()
else:
sys.exit()
case_run()