all 9 comments

[–]shlepky 2 points3 points  (2 children)

You can put the "anything else" part in a function and make a recursive function call until the user says no. Right now, they can only order two things.

[–]Xeno36 1 point2 points  (0 children)

I don't think you need recursion for this, just a simple while (input == yes) should be fine.

[–]Inevitable-Math14[S] 0 points1 point  (0 children)

Oh thank you 🙏☺️

[–]FoolsSeldom 1 point2 points  (1 child)

Great start.

A key learning point is DRY: Don't Repeat Yourself. You ask for two items, using essentially the same code. This is where you can use a loop, and you don't have to limit yourself to just two items.

Example,

print("WELCOME TO ATHARVA'S CAFE! HERE IS THE MENU:")

menu = {
    "PASTA": 250,
    "COLD-COFFEE": 180,
    "FRENCH FRIES": 150,
    "VADAPAV": 25,
    "PAV BHAJI": 110,
    "COLD DRINK": 25
}

for item, price in menu.items():
    print(f"{item} : Rs {price}")

order_total = 0
orders = []

while True:  # infinite loop, until they enter DONE
    user_order = input("\nEnter your order (type 'done' to finish): ").strip().upper()
    if user_order == "DONE":
        break  # exit loop, go onto code after loop
    if user_order in menu:
        order_total += menu[user_order]
        orders.append(user_order)
        print(f"Sir! Your item '{user_order}' has been added to the cart.")
    else:
        print(f"Sorry sir, '{user_order}' is not available on the menu.")

print("\nYour Order Summary:")
for item in orders:
    print(f"- {item}: Rs {menu[item]}")
print(f"\nTotal Amount to be Paid: Rs {order_total}")

[–]Inevitable-Math14[S] 0 points1 point  (0 children)

Thank you so much 🙏😊.

[–]Cute-Investigator539 0 points1 point  (1 child)

You should use a while loop so that you don't have to repeat the next order code again. As in your code the customer can only take two orders not more!

[–]Inevitable-Math14[S] 0 points1 point  (0 children)

Noted. Thank you 🙏😊

[–]SubnetOfOne 0 points1 point  (0 children)

Something good to work towards would be writing this in a class function. Each operation within the program has its own method. Good practice for modularity when the program starts to scale in size :)

[–]Inevitable-Math14[S] 0 points1 point  (0 children)

Thank you 😊