我最近开始使用python,并开始通过CMD创建一个迷你商店。这是我的代码,我试图添加Except错误,但我的对齐方式不好,你知道我应该在这里修复什么吗?或者是固定的。 这里我要做的是将ValueError添加到所有的Shop_pasirikimas=1,2,3中。另外,您可以查看所有的If,else-elif函数,并检查它们是否正确。如果你这么做,我会非常尊重你。对不起,我的英语不好。另外,我是Python新手
while True:
Shop_Pasirinkimas = input("~ What would you like to buy?\n1. {medis}\n2. {weed}\n3. {gun}\n".format(medis=medis,weed=weed,gun=gun))
if len(Shop_Pasirinkimas) < 1:
sys.exit("SOrry")
elif int(Shop_Pasirinkimas) == 1:
clear()
WoodPirkimo_Skaic = int(input("How much {medis} would you like to buy? ".format(medis=medis) + "Wood Now in Stock - {woodins}\n".format(woodins=Wood_InStock)))
BendraKaina = (WoodPirkimo_Skaic * Wood_Price)
if ballance < BendraKaina or Wood_InStock < WoodPirkimo_Skaic:
clear()
print(Not_Enough_Money + ". Your Ballance: {} Eur\n".format(ballance))
continue
else:
# Price per wood - 3.50
ballance -= ( Wood_Price * WoodPirkimo_Skaic)
Wood_Inventory += WoodPirkimo_Skaic
Wood_InStock -= WoodPirkimo_Skaic
clear()
print("~ In stock of {}, left {}".format(medis,Wood_InStock))
#print("- {} Eur * Successfully bought {} {} for {} Eur.".format(weed,weed,))
print('{} Inventory:'.format(Vardas))
print("~ You have {} {}, {} ammo\n".format(Gun_Inventory,gun,Gun_Ammo_Inventory))
print("~ You have {}, of {}\n".format(Weed_Inventory,weed))
print("~ You have {}, of {}\n".format(Wood_Inventory,medis))
Buymore = input("Would you like to buy anything more?... Yes/No\n")
if "Yes" in Buymore or "yes" in Buymore or "Y" in Buymore or "y" in Buymore:
clear()
continue
elif "No" in Buymore or "no" in Buymore or "n" in Buymore or "n" in Buymore:
break
else:
break
elif int(Shop_Pasirinkimas) == 2:
clear()
WeedPirkimo_Skaic = int(input("How much {weed} would you like to buy?".format(weed=weed) + " Now in Stock - {weedins}\n".format(weedins=Weed_InStock)))
BendraKaina = (WeedPirkimo_Skaic * Weed_Price)
if ballance < BendraKaina:
clear()
print(Not_Enough_Money + ". Your Ballance: {} Eur\n".format(ballance))
continue
elif Weed_InStock < WeedPirkimo_Skaic:
clear()
print(Not_Enough_Money + ". Your Ballance: {} Eur\n".format(ballance))
continue
# Price per Gram - 9.50
ballance -= (Weed_Price * WeedPirkimo_Skaic)
Weed_Inventory += WeedPirkimo_Skaic
Weed_InStock -= WeedPirkimo_Skaic
clear()
print("~ In stock of {}, left {}".format(weed,Weed_InStock))
print("~ Successfully bought {}, Your Ballance is {}\n".format(weed,ballance))
print('Inventory:')
print("~ You have {} {}, {} ammo\n".format(Gun_Inventory,gun,Gun_Ammo_Inventory))
print("~ You have {}, of {}\n".format(Weed_Inventory,weed))
print("~ You have {}, of {}\n".format(Wood_Inventory,medis))
Buymore = input("Would you like to buy anything more?... Yes/No\n")
if "Yes" in Buymore or "yes" in Buymore or "Y" in Buymore or "y" in Buymore:
clear()
continue
elif "No" in Buymore or "no" in Buymore or "N" in Buymore or "n" in Buymore:
break
else:
break
# NO MONEY, NOT IN STOCK - WORKING
elif int(Shop_Pasirinkimas) == 3:
clear()
GunPirkimo_Skaic = int(input("How much {gun} would you like to buy? ".format(gun=gun) + "\nShotun Now in Stock - {gunins}\n".format(gunins=Gun_InStock)))
BendraKaina = (GunPirkimo_Skaic * Gun_Price)
if ballance < BendraKaina:
clear()
print(Not_Enough_Money + ". Your Ballance: {} Eur\n".format(ballance))
continue
# Nebeliko Storage.
elif Gun_Ammo_InStock < (GunPirkimo_Skaic * 30):
clear()
print("* No more left in stock : \n {} Left - {}\n {} Left - {}\n".format(gun,Gun_InStock,gun_ammo,Gun_Ammo_InStock))
else:
ballance -= (Gun_Price * GunPirkimo_Skaic)
Gun_Inventory += GunPirkimo_Skaic
Gun_InStock -= GunPirkimo_Skaic
Gun_Ammo_InStock -= (GunPirkimo_Skaic * 30)
Gun_Ammo_Inventory += (GunPirkimo_Skaic * 30)
clear()
print("~ In stock of {}, left {}".format(gun,Gun_InStock))
print("~ Successfully bought {}, Your Ballance is {}\n".format(gun,ballance))
print('Inventory:')
print("~ You have {} {}, {} ammo\n".format(Gun_Inventory,gun,Gun_Ammo_Inventory))
print("~ You have {}, of {}\n".format(Weed_Inventory,weed))
print("~ You have {}, of {}\n".format(Wood_Inventory,medis))
if Gun_Ammo_Inventory <= 30:
BuyMoreAmmo = input("~ You have only {}, Maybe you would like to buy any More gun Ammo?... Yes/No\n".format(Gun_Ammo_Inventory))
if "Yes" in BuyMoreAmmo or "yes" in BuyMoreAmmo or "Y" in BuyMoreAmmo or "y" in BuyMoreAmmo:
clear()
AmmoPirkimo_Skaic = int(input("~ 30x Ammo for {}, costs. How much Ammo Packets you would like to buy?".format(gun,Gun_Ammo_Price)))
if Gun_Ammo_InStock < BendraKaina:
clear()
print(Not_Enough_Money + ". Your Ballance: {} Eur\n".format(ballance))
continue
ballance -= (AmmoPirkimo_Skaic * Gun_Ammo_Price)
Gun_Ammo_InStock -= (AmmoPirkimo_Skaic * 30)
Gun_Ammo_Inventory += (AmmoPirkimo_Skaic * 30)
print("You have {} bullets".format(Gun_Ammo_Inventory))
print("Ammo Left in stock {} bullets".format(Gun_Ammo_InStock))
elif "No" in BuyMoreAmmo or "no" in BuyMoreAmmo or "N" in BuyMoreAmmo or "n" in BuyMoreAmmo:
sys.exit("Byee")
else:
sys.exit("Byeee!")
else:
Buymore = input("Would you like to buy anything more?... Yes/No\n")
if " " in Buymore or len(Buymore) < 1:
print("SOrry")
continue
elif "Yes" in Buymore or "yes" in Buymore or "Y" in Buymore or "y" in Buymore:
clear()
continue
elif "No" in Buymore or "no" in Buymore or "N" in Buymore or "n" in Buymore:
break
else:
break
"""
while True:
UserName = input("What Username you want?")
if len(UserName) <= 1:
print("Bad")
else:
ballance -= 500
print("Account created {}, Ballance = {}".format(UserName,ballance))
你不需要
try/except
。不要使用int(Shop_Pasirinkimas)
,只需将输入与字符串进行比较:相关问题 更多 >
编程相关推荐