我正在尝试创建一个类似POS系统的菜单。我有我的礼品卡余额和他们的号码,我试图把这个纳入菜单。例如,在菜单中,如果用户单击数字“1”,我希望菜单提示用户输入礼品卡号,用户需要在其中输入正确的礼品卡号(giftnum1)。如果用户未单击有效号码或未输入正确的礼品卡,我希望菜单要求用户单击有效号码,或者如果用户输入错误的礼品卡号,我希望菜单要求用户检查礼品卡号并重试。我在这方面是新的,所以我知道我的大多数菜单代码是错误的,可以以某种方式加以纠正,但我不知道如何做到这一点,所有其他与此相关的职位没有意义,这篇文章。
这是我的代码:
gift1 = 100
gift2 = 13.50
gift3 = 67.40
giftnum1 = 123456
giftnum2 = 998765
giftnum3 = 456789
print("Here are your current gift cards with the current balances: " + "$" + str(gift1) + " with the gift \ncard number of " + str(giftnum1) + ", $" + str(gift2) + " with a gift card number of " + str(giftnum2) + ", and $" + str(gift3) + " with a gift card number of " + str(giftnum3) + ".")
#making the POS system
def itemmenu():
print ("Here are the current items with their price. You must choose the correct gift card to go along with the item.")
print ("1. Nike Shoes ($100)")
print ("2. Bluetooth Headphones ($67.40)")
print ("3. Gloves ($13.50)")
print ("4. Exit")
loop = True
while loop:
itemmenu()
buyitems = int(input("Enter the number corresponding to the item that you would like to buy: "))
if buyitems == 1:
input("Please enter the correct gift card to buy the Nike Shoes: ")
if buyitems == giftnum1:
print("You have successfully entered the correct gift card to buy the Nike Shoes, please follow the directions to be sent a confirmation email.")
if buyitems != giftnum1:
print("You have entered an incorrect gift card number.")
elif buyitems == 2:
input("Please enter the correct gift card to but the Bluetooth Headphones: ")
if buyitems == giftnum2:
print("You have successfully entered the correct gift card to buy the Bluetooth Headphones, please follow the directions to be sent a confirmation email.")