我的代码如下所示:
shop = input("Do you want to enter the shop?")
if shop == "y":
print ("["+shopownername+"]: Welcome to my store.")
sleep(1)
print ("["+shopownername+"]: Here are the items for sale:")
for x in shopitems:
print (x)
sleep(1)
print ("You have "+str(gold)+" gold.")
sleep(1)
choice = 0
while choice != "exit":
choice = input("What would you like to buy? Type 'exit' and enter to leave.")
if choice == "a":
purchase = "a"
confirm = input("Are you sure you want to buy "+purchase+"? (y/n)")
if confirm == "y":
if "a" in weapons:
print ("You already have that.")
break
elif gold < shopitems[purchase]:
print ("You do not have enough gold for that.")
break
else:
gold = gold - shopitems[purchase]
weapons.append("a")
print ("You have purchased the "+purchase+".")
print ("You now have "+str(gold)+" gold.")
break
elif choice == "b":
purchase = "b"
confirm = input("Are you sure you want to buy "+purchase+"? (y/n)")
if confirm == "y":
if "b" in weapons:
print ("You already have that.")
break
elif gold < shopitems[purchase]:
print ("You do not have enough gold for that.")
break
else:
gold = gold - shopitems[purchase]
weapons.append("b")
print ("You have purchased the "+purchase+".")
print ("You now have "+str(gold)+" gold.")
break
else:
print ("["+shopownername+"]: Thank you for coming.")
else:
print ("You did not enter the shop.")
它应该做的是,在任何情况下,直到您退出商店,您将能够购买物品。然而,在这个系统中,它也打破了时间,并继续下一段代码。我应该做的是尝试买一个,无论我买不起,已经拥有它,或买了它,都可以试图买b或者试图重新购买。 我该怎么办?