How to create menu in Python with multiple if statements

I’m trying to create a menu for a POS like system. I have my gift card balances with their numbers and I’m trying to incorporate this in a menu. In the menu for example, if a user click the number ‘1’, I want the menu to prompt the user for the gift card number in which they will need to enter the correct gift card number (giftnum1). If the user does not click on a valid number or does not enter the correct gift card, I would like the menu to ask the user to click on a valid number or if the user enters the wrong gift card number, I would like for the menu to ask the user to check the gift card number and try again. I am new at this, so I know that most of my menu code is wrong and could be corrected somehow, but I’m not sure how to do this and all other posts relating to this do not make sense with this post.

Here is my code that I have:

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.")

    

Answer

Please try below code :

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:
        while loop:
            giftcardno = int(input("Please enter the correct gift card to buy the Nike Shoes: "))
            if giftcardno == 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.")
                break
            else:
                print("You have entered an incorrect gift card number. Try again")
    elif buyitems == 2:
        giftcardno = input("Please enter the correct gift card to but the Bluetooth Headphones: ")
        if giftcardno == 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.")
        else:
            print("You have entered an incorrect gift card number. Try ag")
    else:
        break 

enter image description here

Leave a Reply

Your email address will not be published. Required fields are marked *