Python Forum
School project -- need help with it it says syntax error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
School project -- need help with it it says syntax error
#1
Shocked 
Hi,

I have a year 7 school project due in 1 week. Cant figure out why it wont work. Please help. The program I use wont tell me where the error is. Does anything stand out?

TOTAL = int(0)

print(" Hello, welcome to Bazing cafe what is your full name")
def get_firstname():
    firstname = input("enter your first name")
    return firstname
def get_lastname():
    lastname = input("enter your last name")
    return lastname

def drinks():
    print("Drinks menu")
    print("1.Juice Oringe $3.00")
    print("2.Juice apple $3.00")
    print("3.Juice black current $3.00")
    print("4.milkshake chocolate $4.50")
    print("5.milkshake strawberry $4.50")
    print("6.milkshake vanilla $4.50")
    print("7.milkshake caramel $4.50")

def main_meals():
    print("Main meals")
    print("1.kids schnitti $7.99")
    print("2.mini chicken burger $6.00")
    print("3.mini beef burger $6.00")
    print("4.spaghetti $8.00")
    print("5.lasagne $7.50")
def A_DRINKS():
    print("1.beer $9.15")
    print("2.wine $18.00")
    print("3.gin $16.00")
    print("4.mocktail $22.00")

def A_MAIN_MEALS():
    print("1.beef burger $16.50")
    print("2.chicken burger $16.50")
    print("3.wagyu burger $29.99")
    print("4.roast chicken $15.99")
    print("5.special soup $11.50")
    print("6.salad of the day $12.99")
    
    
    
                     
if __name__=="__main__":
    firstname = get_firstname()
    lastname = get_lastname()
    print("hello", firstname, lastname)

num = int(input("how old are you "))
drink()
answer = int(input("type the number of your choice"))
if answer == 1:
    TOTAL = TOTAL + 3
    elif answer == 2:
        TOTAL = TOTAL + 3
        elif answer == 3:
            TOTAL = TOTAL + 3
            elif answer == 4:
                TOTAL = TOTAL + 4.5
                elif answer == 5:
                    TOTAL = TOTAL + 4.5
                    elif answer == 6:
                        TOTAL = TOTAL + 4.5
                        elif answer == 7:
                            TOTAL = TOTAL + 4.5
                            main_meals()
                            answer = int(input("type the number of your choice"))
                            if answer ==1:
                                TOTAL = TOTAL + 7.99
                                elif answer ==2:
                                    TOTAL = TOTAL + 6
                                    elif answer ==3:
                                        TOTAL = TOTAL + 6
                                        elif answer ==4:
                                            TOTAL = TOTAL + 8
                                            elif answer ==5:
                                                TOTAL = TOTAL + 7.5
                                                print(" total price =$" + TOTAL)
                                                print("adult menus")
                                                A_DRINKS
                                                answer = int(input("type the number of your choice"))
                                                if answer ==1:
                                                    TOTAL = TOTAL + 9.15
                                                    elif aswer ==2:
                                                        TOTAL = TOTAL + 18
                                                        elif answer ==3:
                                                            TOTAL = TOTAL +16
                                                            elif answer ==4:
                                                                TOTAL = TOTAL +22
                                                                answer = int(input("type the number of your choice"))
                                                                A_MAIN_MEALS
                                                                if answer ==1:
                                                                    TOTAL = TOTAL + 16.50
                                                                    elif answer ==2:
                                                                        TOTAL = TOTAL + 16.50
                                                                        elif answer ==3:
                                                                            TOTAL = TOTAL + 29.99
                                                                            elif answer ==4:
                                                                                TOTAL = TOTAL + 15.99
                                                                                elif answer ==5:
                                                                                    TOTAL = TOTAL + 11.50
                                                                                    elif answer ==6:
                                                                                        TOTAL = TOTAL + 12.99
                                                                                        print(" cost =$" +TOTAL)
Yoriz write May-23-2021, 09:00 AM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#2
drink is not defined it's defined as drinks
The indentation on the elif's is wrong, elif should be at the same indentation as its matching if.
Reply
#3
thanks
Reply
#4
Also in line 81 you have A_DRINKS without parentheses, so it will not call the function. Same problem in 92.

And, your indentation on all of those elif's is wrong

And, can you think of a better way to do this than the large cascade of elifs?
Reply
#5
That is some ugly code. You need an abstraction.

Your program has menus, menu items and menu item prices. Your program displays menu items, takes an order, and computes a total. The things your program has are going to become variables. The things your program does are going to become functions. If you come up with a good abstraction for your program's objects (menu, menu items, menu prices) it makes it easy to write the functions that work with these objects. If the functions are well designed it makes it easy to use them to make complicated programs, like taking someone's order.

A menu item is a description of the food. Each menu item has a price. The prices should somehow be associated with the menu item so you can get the price if you know the item. A menu is a collection of menu items. Right now your program doesn't have any code that really represents these things that are central to your program. You have strings for your menu, but the strings include not only the description, but the price, and an order number as well. There is no way to get the price of a menu item.

If I was writing this program I would make the menus a dictionary, and the menu items would be items in the dictionary. I use the menu item description as the dictionary key. I use the menu item prices as the dictionary value. The menu dictionary lets me use the key (description) to get the value (price). Like menu items are grouped by putting them in the same dictionary. This is a dictionary of all the main meal items.
main_meals = {
    "kids schnitti": 7.99,
    "mini chicken burger": 6.00,
    ".mini beef burger": 6.00,
    "spaghetti": 8.00,
    "lasagne": 7.50,
}
Now if I want to know the price of lasagne I can ask the menu.
print(main_meals["lasagne")
Output:
7.5
I could make a similar menu for drinks.
drinks = {
    "Juice Oringe": 3.00,
    "Juice apple": 3.00,
    "Juice black current": 3.00,
    "milkshake chocolate": 4.50,
    "milkshake strawberry": 4.50,
    "milkshake vanilla": 4.50,
    "milkshake caramel": 4.50,
}
Notice that the main_meals menu have the same structure. They also offer the same functions for working with the menu. Since the main meal and drinks menus work work the same way, I can write code that works with menus, not specific menus. I write a function that takes an order using the GENERIC idea of a menu, not a particular menu. This is abstraction.
def take_order(menu, name=None):
    """Take order from user.
    menu : dictionary of items you can order
    category : What type of items are in menu.  Optional

    returns selected item and item price
    """
    print()
    if name:
        print(name)

    choices = {}
    for index, item in enumerate(menu):
        index = str(index + 1)
        choices.update({index: item})
        price_str = f"${menu[item]:.2f}"
        print(f"{index:>2} {item:{20}} {price_str:>8}")

    choice = input("Enter the number of your choice ")
    item = choices[choice]
    price = menu[item]
    return item, price

print(take_order(drinks, "Drinks")
Output:
Drinks 1 Juice Oringe $3.00 2 Juice apple $3.00 3 Juice black current $3.00 4 milkshake chocolate $4.50 5 milkshake strawberry $4.50 6 milkshake vanilla $4.50 7 milkshake caramel $4.50 Enter the number of your choice 4 ('milkshake chocolate', 4.5)
I can reuse this function to take your meal order or your drink order or you desert order or any order that is associated with a menu.
Reply
#6
This is an old thread that has been bumped with a "thanks" for some reason.
Don't expect to get a response from the OP
Reply
#7
I think Estherbarnes is a robot. Most responses are very vague. Should have checked the date. Duh!
ndc85430 likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  my python project for school vavervirus 2 642 Oct-12-2023, 03:28 AM
Last Post: buran
  School project janivar91 3 2,717 Jan-23-2021, 06:31 AM
Last Post: KonohaHokage
  Python School Project andreas30298 2 2,142 Nov-12-2020, 09:58 AM
Last Post: Axel_Erfurt
  I'm getting a syntax error very early on in my code and I can't quite figure it out. liloliveoil 1 2,005 Oct-30-2020, 05:03 AM
Last Post: deanhystad
  Unspecified syntax error hhydration 1 2,008 Oct-25-2020, 10:45 AM
Last Post: ibreeden
  Annuity function for school - syntax error peterp 2 1,979 Oct-12-2020, 10:34 PM
Last Post: jefsummers
  Invalid syntax error, where? tucktuck9 2 3,426 May-03-2020, 09:40 AM
Last Post: pyzyx3qwerty
  project error code pkmnmewtwo 2 23,294 May-02-2020, 12:40 PM
Last Post: ndc85430
  Raise an exception for syntax error sbabu 8 3,161 Feb-10-2020, 01:57 AM
Last Post: sbabu
  syntax error: can't assign to operator liam 3 4,052 Jan-25-2020, 03:40 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020