0% found this document useful (0 votes)
3 views4 pages

Python Task

PyBrew Cafe requires a simple ordering program for counter staff to process customer orders and print receipts. The program must display a menu, take customer orders, calculate subtotals, apply a loyalty discount for orders over $20, and include tax in the final receipt. The provided code outlines the implementation of these requirements, including user input handling and calculations.

Uploaded by

Maxwell Aidoo
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views4 pages

Python Task

PyBrew Cafe requires a simple ordering program for counter staff to process customer orders and print receipts. The program must display a menu, take customer orders, calculate subtotals, apply a loyalty discount for orders over $20, and include tax in the final receipt. The provided code outlines the implementation of these requirements, including user input handling and calculations.

Uploaded by

Maxwell Aidoo
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

PyBrew Cafe

Python Programming Task

PART 1: The Task (Student Copy)


Scenario
You have been hired by PyBrew Cafe to build a simple ordering program for their counter staff.
When a customer walks in, the staff types in their order and the program prints a receipt with the
total. The cafe owner also wants a loyalty discount to reward bigger spenders.

The Menu
# Item Price
1 Coffee $3.50
2 Tea $2.00
3 Sandwich $5.50
4 Muffin $3.00

What Your Program Must Do


• Display a welcome message and the menu when it starts
• Ask for the customer's name
• Ask how many different items they want to order (between 1 and 4)
• Use a for loop to go through each item the customer wants:
• Ask which item number they want (1–4)
• Ask how many of that item they want
• Calculate and display the cost for that item
• Calculate a subtotal across all items
• Apply a 10% loyalty discount if the subtotal is $20.00 or more, and tell the customer
they’ve earned it
• Add 8% tax to the (possibly discounted) subtotal
• Print a final receipt showing the customer’s name, subtotal, tax, and the grand total
PART 2: The Answer
Full Solution Code
# ============================================================
# PyBrew Cafe - Order System
# ============================================================

# --- Menu prices stored as variables ---


price_coffee = 3.50
price_tea = 2.00
price_sandwich = 5.50
price_muffin = 3.00

# --- Welcome & Menu Display ---


print("=" * 38)
print(" Welcome to PyBrew Cafe!")
print("=" * 38)
print(" 1. Coffee - $3.50")
print(" 2. Tea - $2.00")
print(" 3. Sandwich - $5.50")
print(" 4. Muffin - $3.00")
print("=" * 38)

# --- Customer Details ---


customer_name = input("\nEnter customer name: ")
num_items = int(input("How many different items to order? (1-4): "))

# --- Order Loop ---


subtotal = 0

for i in range(1, num_items + 1):


print("\n--- Item", i, "---")
choice = input("Enter item number (1-4): ")
quantity = int(input("Enter quantity: "))

if choice == "1":
item_cost = price_coffee * quantity
print("Coffee x" + str(quantity) + " = $" + str(round(item_cost, 2)))
elif choice == "2":
item_cost = price_tea * quantity
print("Tea x" + str(quantity) + " = $" + str(round(item_cost, 2)))
elif choice == "3":
item_cost = price_sandwich * quantity
print("Sandwich x" + str(quantity) + " = $" + str(round(item_cost, 2)))
elif choice == "4":
item_cost = price_muffin * quantity
print("Muffin x" + str(quantity) + " = $" + str(round(item_cost, 2)))
else:
print("Invalid item number - skipping this item.")
item_cost = 0

subtotal = subtotal + item_cost

# --- Loyalty Discount ---


print("\n--- Order Summary ---")
print("Subtotal: $" + str(round(subtotal, 2)))

if subtotal >= 20:


discount = subtotal * 0.10
subtotal = subtotal - discount
print("Loyalty discount (10%): -$" + str(round(discount, 2)))
print("Congratulations! You earned a loyalty discount!")

# --- Tax Calculation ---


tax = subtotal * 0.08
grand_total = subtotal + tax

# --- Receipt ---


print("\n" + "=" * 38)
print(" Receipt for " + customer_name)
print("=" * 38)
print("Subtotal : $" + str(round(subtotal, 2)))
print("Tax (8%) : $" + str(round(tax, 2)))
print("TOTAL : $" + str(round(grand_total, 2)))
print("=" * 38)
print(" Thank you for visiting PyBrew Cafe!")
print("=" * 38)

Skills Breakdown
Skill Where It's Used
print() Welcome screen, menu, receipt, item confirmations
input() Customer name, item choices, quantities
Data types str for name/choice, int for quantity, float for prices
Variables All prices, subtotal, tax, grand total, discount
Calculations item_cost, subtotal, discount, tax, grand_total
Selection if/elif/else for menu choice & loyalty discount check
For loop Repeats the ordering process for each item

Sample Output
======================================
Welcome to PyBrew Cafe!
======================================
1. Coffee - $3.50
2. Tea - $2.00
3. Sandwich - $5.50
4. Muffin - $3.00
======================================

Enter customer name: Sarah


How many different items to order? (1-4): 2

--- Item 1 ---


Enter item number (1-4): 1
Enter quantity: 2
Coffee x2 = $7.0
--- Item 2 ---
Enter item number (1-4): 3
Enter quantity: 3
Sandwich x3 = $16.5

--- Order Summary ---


Subtotal: $23.5
Loyalty discount (10%): -$2.35
Congratulations! You earned a loyalty discount!

======================================
Receipt for Sarah
======================================
Subtotal : $21.15
Tax (8%) : $1.69
TOTAL : $22.84
======================================
Thank you for visiting PyBrew Cafe!
======================================

You might also like