python 3.x - How to break only one nested loop? -
my code appears this:
shop = input("do want enter shop?") if shop == "y": print ("["+shopownername+"]: welcome store.") sleep(1) print ("["+shopownername+"]: here items sale:") x in shopitems: print (x) sleep(1) print ("you have "+str(gold)+" gold.") sleep(1) choice = 0 while choice != "exit": choice = input("what buy? type 'exit' , enter leave.") if choice == "a": purchase = "a" confirm = input("are sure want buy "+purchase+"? (y/n)") if confirm == "y": if "a" in weapons: print ("you have that.") break elif gold < shopitems[purchase]: print ("you not have enough gold that.") break else: gold = gold - shopitems[purchase] weapons.append("a") print ("you have purchased "+purchase+".") print ("you have "+str(gold)+" gold.") break elif choice == "b": purchase = "b" confirm = input("are sure want buy "+purchase+"? (y/n)") if confirm == "y": if "b" in weapons: print ("you have that.") break elif gold < shopitems[purchase]: print ("you not have enough gold that.") break else: gold = gold - shopitems[purchase] weapons.append("b") print ("you have purchased "+purchase+".") print ("you have "+str(gold)+" gold.") break else: print ("["+shopownername+"]: thank coming.") else: print ("you did not enter shop.") what supposed in case until exit shop, able buy items. however, in system, breaks while well, , proceeds next piece of code. should able try buy a, , no matter if cannot afford it, own it, or have bought it, can both attempt buy b or try re-buy a. should do?
Comments
Post a Comment