python 包含语句,如何在Python中创建包含多个if语句的菜单

我正在尝试创建一个类似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.")

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值