-1

What I wrote

if membership_card in [123456, 5678901, 234567, 345678, 456789, 901234]: print('Your membership card number have been confirm \nWith this you will have 10% discount for your every ' 'purchased') print('Ok, then here are the menu\n' + menu) order = input('What do you like to order?\n') Quantity = input("How many would you like?\n") good_to_go = True while not good_to_go: if order == 'Americano': price = 4 good_to_go = True

        elif order == 'Latte':
            price = 7
            good_to_go = True
            whipping_cream_good_to_go = False

            while not whipping_cream_good_to_go:
                add_on = input('Do u want whipping cream\n')
                if add_on == 'Yes':
                    price = 11
                    whipping_cream_good_to_go = True
                if not whipping_cream_good_to_go:
                    print('Invalid syntax')
        elif order == 'Cappuccino':
            price = 9
            good_to_go = True

        elif order == 'Espresso':
            price = 10
            good_to_go = True

        elif order == 'Black Coffe':
            price = 3
            good_to_go = True

    total = price * int(Quantity)
    print('and the total of it is\n' + str(total))

What i Got

total = price * int(Quantity)
        ^^^^^

NameError: name 'price' is not defined. Did you mean: 'print'?

a solution to my python problem

1 Answers1

0

It seems you didn't give price the initial value , and in the process price didn't get any value so at the end it is undefined.

Above all the elifs and ifs just give the price a value and the error you just got won't appear again.

Hosseinreza
  • 561
  • 7
  • 18
  • Then how do need to do to solve it cause i have try various idea but none work @Hosseinreza – The Crazy Dude Really Feb 24 '23 at 05:54
  • @TheCrazyDudeReally can you share all the code? – Hosseinreza Feb 24 '23 at 05:55
  • if order == 'Americano': price = 4 good_to_go = True elif order == 'Latte': price = 7 good_to_go = True whipping_cream_good_to_go = False – The Crazy Dude Really Feb 24 '23 at 06:34
  • while not whipping_cream_good_to_go: add_on = input('Do u want whipping cream\n') if add_on == 'Yes': price = 11 whipping_cream_good_to_go = True if not whipping_cream_good_to_go: print('Invalid syntax') elif order == 'Cappuccino': price = 9 good_to_go = True – The Crazy Dude Really Feb 24 '23 at 06:35
  • elif order == 'Espresso': price = 10 good_to_go = True elif order == 'Black Coffe': price = 3 good_to_go = True total = price * int(Quantity) print('and the total of it is\n' + str(total)) – The Crazy Dude Really Feb 24 '23 at 06:36
  • else: print("Your membership card is not in the system") retype_membership_card_number = input('Please retype your membership card\n') if retype_membership_card_number in [123456, 5678901, 234567, 345678, 456789, 901234]: print('Your number have been confirmed') print('Ok, then here are the menu\n' + menu) order = input('What do you like to order?\n') good_to_go = True while not good_to_go: – The Crazy Dude Really Feb 24 '23 at 06:36
  • if order == 'Americano': price = 4 good_to_go = True elif order == 'Latte': price = 7 good_to_go = True whipping_cream_good_to_go = False – The Crazy Dude Really Feb 24 '23 at 06:37
  • while not whipping_cream_good_to_go: add_on = input('Do u want whipping cream\n') if add_on == 'Yes': price = 11 whipping_cream_good_to_go = True if not whipping_cream_good_to_go: print('Invalid syntax') elif order == 'Cappuccino': price = 9 good_to_go = True – The Crazy Dude Really Feb 24 '23 at 06:37
  • elif order == 'Espresso': price = 10 good_to_go = True elif order == 'Black Coffe': price = 3 good_to_go = True else: print('Invalid Syntax') exit() – The Crazy Dude Really Feb 24 '23 at 06:38
  • else: print('Ok, then here are the menu\n' + menu) order = input('What do you like to order?\n') ready = True while not ready: if order == 'Americano': price = 4 ready = True elif order == 'Latte': price = 7 ready = True whipping_cream_add_on = False – The Crazy Dude Really Feb 24 '23 at 06:38
  • while not whipping_cream_add_on: add_on = input('Do u want whipping cream\n') if add_on == 'Yes': price = 11 whipping_cream_add_on = True if not whipping_cream_add_on: print('Invalid syntax') – The Crazy Dude Really Feb 24 '23 at 06:38
  • elif order == 'Cappuccino': price = 9 ready = True elif order == 'Espresso': price = 10 ready = True elif order == 'Black Coffe': price = 3 ready = True – The Crazy Dude Really Feb 24 '23 at 06:38