Python Programs Written and Practiced by : Jiya Kiyam

File Name : restaurant.py

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"""
Program Name: Restaurant Billing System
Description: i) Show food item with prices ii) Take the user's order(multiple) iii) Calculate total bill iv) Apply 10% discount if bill is above ₹500 e) Exit option to close billing
"""
def add_to_order(item_name, price, qty):
    item_total = price * qty
    order.append((item_name, qty, item_total))
    print(f"Added {qty} x {item_name}")


def calculate_total():
    subtotal = 0
    for item in order:
        subtotal += item[2]  # item[2] is the item_total
    return subtotal


def apply_discount(subtotal):
    if subtotal > 500:
        return subtotal * 0.10  # 10% discount
    return 0

order = []

while True:
    print("\n--- MENU ---")
    print("1. Burger       - ₹120")
    print("2. Pizza        - ₹350")
    print("3. Pasta        - ₹220")
    print("4. French Fries - ₹90")
    print("5. Cold Drink   - ₹50")
    print("6. Checkout & Bill")
    print("7. Exit")

    choice = input("Select an option (1-7): ")

    match choice:
        case "1":
            qty = int(input("Enter quantity: "))
            add_to_order("Burger", 120, qty)

        case "2":
            qty = int(input("Enter quantity: "))
            add_to_order("Pizza", 350, qty)

        case "3":
            qty = int(input("Enter quantity: "))
            add_to_order("Pasta", 220, qty)

        case "4":
            qty = int(input("Enter quantity: "))
            add_to_order("French Fries", 90, qty)

        case "5":
            qty = int(input("Enter quantity: "))
            add_to_order("Cold Drink", 50, qty)

        case "6":
            if len(order) == 0:
                print("Your order is empty!")
            else:
                subtotal = calculate_total()
                discount = apply_discount(subtotal)
                final_bill = subtotal - discount

                print("\n--- YOUR BILL ---")
                for name, q, amt in order:
                    print(f"{name} x {q} = ₹{amt}")

                print(f"Subtotal: ₹{subtotal}")
                print(f"Discount: ₹{discount}")
                print(f"Total Amount to Pay: ₹{final_bill}")
                break

        case "7":
            print("Exiting. Thank you!")
            break
        case _:
            print("Invalid choice! Try again.")

Run Back to programs