#πŸ”’ ASAP Help

48 messages Β· Page 1 of 1 (latest)

twilit pike
#
# Exercise 1:
def print_offerings():
    print("Welcome to the bakery! Here is our menu:")
    menu={"baguette":4.75,"croissant":2.95,"chocolatine":3.30}
    for food in menu:
        print(f'{food:12s}     ${menu[food]:.2f}')
print_offerings()


def order_menu():
    price=0.0
    menu={"baguette":4.75,"croissant":2.95,"chocolatine":3.30}
    while True:
        choice=(input("What would you like to order (enter Q to quit):")).lower()
        if choice=="Q":
            break
        if choice in menu:
            number=int(input("How many croissant would youn like?"))
            price=menu[choice]*number+price
            print(f'Total so far {price:.2f}')
order_menu()

def print_receipt(order: dict, total: float):
    menu={"baguette":4.75,"croissant":2.95,"chocolatine":3.30}
    print("You ordered:")
    print(f'{Qty.} {Item}       {Unit}  {Price}  {Subtotal}')
    for food in choice:
gaunt perchBOT
#

@twilit pike

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

twilit pike
#

im kinda stuck on this last part

#

final result should be like thsi:

#

im stuck on this here:

glacial pumice
#

First the trivial. This:

    print(f'{Qty.} {Item}       {Unit}  {Price}  {Subtotal}')

should probably just be:

    print('Qty. Item       Unit  Price  Subtotal')

A format string (aka an f-string), the f'.....' string syntax, _replaces the {......} bits with the value of the expression inside them. For this heading you just want to print the heading.

twilit pike
#

ok

glacial pumice
#

It should like you need to have gathered a choices variable representing what the customer ordered. Probably a dict whose keys are the menu item key and whose values are the quantity.
I think you should be constructing that in the order_menu() function and having that function return it. So eg in that function put:

    choices = {} # empty dict - nothing yet ordered

and at the bottom:

     return choices

and the bits in the middle should add an entry to the choices ict when an order is entered.

#

Then you can call it as:

choices = order_menu()

and that gets you the order, which you can pass to print_receipt as the first parameter (i.e. order inside that function).

twilit pike
glacial pumice
#

Then your for-loop in the receipt function can iterate over the order:

for food, quantity in order.items():

The .items() produces (food,quantity) 2-tuples from the order, and the for then unpacks those into the food, quantity variables. Which you then use inside the loop to print that row of the order in the receipt.

#

I'd start with just printing the values for the receipt rows first - the quantity, the food item, and calculated prices.
Then pretty up the alignment later, after those numbers are correct.

twilit pike
glacial pumice
#

Oh, in case that food item key is already there?

#

Like ordering baguettes, and then again baguettes?

twilit pike
#

yes

glacial pumice
#

Yeah, you could go:

choices[key] = choices.get(key,0) + quanity
twilit pike
#

likes this?

#
if choice in menu:
            number=int(input("How many croissant would youn like?"))
            price=menu[choice]*number+price
            choices[key]=choices.get(key,0)+number
            print(f'Total so far {price:.2f}')
glacial pumice
#

Looks ok to me.

twilit pike
#
def print_offerings():
    print("Welcome to the bakery! Here is our menu:")
    menu={"baguette":4.75,"croissant":2.95,"chocolatine":3.30}
    for food in menu:
        print(f'{food:12s}     ${menu[food]:.2f}')
print_offerings()
    


def order_menu():
    choices={}
    price=0.0
    menu={"baguette":4.75,"croissant":2.95,"chocolatine":3.30}
    while True:
        choice=input("What would you like to order (enter Q to quit):").lower()
        if choice=="q":
            break
        if choice in menu:
            number=int(input(f'How many {choice} would you like?'))
            price=menu[choice]*number+price
            choices[choice]=choices.get(choice,0)+number
            print(f'Total so far {price:.2f}')
    return choices,price
order_menu()


def print_receipt(order: dict, total: float):
    subtotal=0.0
    total=0.0
    order,total=order_menu()
    menu={"baguette":4.75,"croissant":2.95,"chocolatine":3.30}
    print("You ordered:")
    print('{Qty.}{Item:5s}{Unit:20s}{Price:25s}{Subtotal:31s}')
    for food,quantity in choices.items():
        stuff=menu[food]
        subtotal=stuff*quantity
        print(f' {quantity}{food}${stuff:.2f}${subtotal:.2f}')
    print(f'Your total is ${total:.2f}')
#

the print_receipt function is still not printing idk why

wild perch
#

uh you have two posts #1435821183084920923 ?

twilit pike
#

yes

twilit pike
wild perch
#

up till which line in your code does it stop/not work? i can't seem to connect it with the image

twilit pike
#

the print_receipt function stopped working

wild perch
twilit pike
#

ok i did that, but choices is undefined

#

somehow

wild perch
twilit pike
#

no

#

what does it do?

wild perch
#

you did...

wild perch
# twilit pike ```py # Exercise 1: def print_offerings(): print("Welcome to the bakery! Her...
def print_receipt(order: dict, total: float):
    subtotal=0.0
    total=0.0
    order,total=order_menu() # This line here
    menu={"baguette":4.75,"croissant":2.95,"chocolatine":3.30}
    print("You ordered:")
    print('{Qty.}{Item:5s}{Unit:20s}{Price:25s}{Subtotal:31s}')
    for food,quantity in choices.items():
        stuff=menu[food]
        subtotal=stuff*quantity
        print(f' {quantity}{food}${stuff:.2f}${subtotal:.2f}')
    print(f'Your total is ${total:.2f}')
twilit pike
#

but it still isnt working

wild perch
# twilit pike but it still isnt working
def order_menu():
    choices={}
    price=0.0
    menu={"baguette":4.75,"croissant":2.95,"chocolatine":3.30}
    while True:
        choice=input("What would you like to order (enter Q to quit):").lower()
        if choice=="q":
            break
        if choice in menu:
            number=int(input(f'How many {choice} would you like?'))
            price=menu[choice]*number+price
            choices[choice]=choices.get(choice,0)+number
            print(f'Total so far {price:.2f}')
    return choices, price # here you are returning two values, the name of the values won't carry over when u call a function

order, total = order_menu() # 'order' is the 'choices' and 'total' is the 'price'

# Since the name of the variable you return does not carry over
# This also works and is the same thing:
food, bill = order_menu()
twilit pike
#

now i have unhashable

#

what does it mean

digital oar
#

can you show what your code looks like now? seems like it's gone over a lot of iterations

#

menu[order] <--- in here, order is a dictionary, which is not "hashable" and therefore can't be used as a key for another dictionary

#

The general rule is only immutable things are hashable, like numbers, strings, or tuples (if their contents can't change)

gaunt perchBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.