Food Order
Python Exercises
🍽️ Python Mini Project: Online Restaurant Order App
In this activity, you’ll create a
restaurant ordering system that shows menus,
calculates totals, and simulates food preparation! 🧑🍳
🧩 Step-by-Step Instructions:
-
Import the
timemodule
This will help you create a delay when the food is being “prepared”.import time -
Create a menu dictionary with items and prices
This makes your menu easy to manage.menu = {
"1": ("Burger", 30000),
"2": ("Pizza", 45000),
"3": ("Pasta", 40000)
} -
Display the menu to the user
Show each food and its price with numbers to choose from.print("🍔 Welcome to Python Restaurant!")
for key, item in menu.items():
print(f"{key}. {item[0]} — Rp{item[1]}") -
Ask the user to select an item
Use number input (1, 2, or 3).choice = input("Select your menu number: ")
food, price = menu[choice] -
Ask for quantity
Multiply by price to get total cost.qty = int(input("Enter quantity: "))
total = price * qty -
Ask for extras (drinks or desserts)
Show options and add to the total if chosen.extra_choice = input("Would you like a drink or cake? (yes/no): ")
if extra_choice.lower() == "yes":
total += 10000
print("Added drink or cake Rp10000")
-
Ask for customer’s name
name = input("Enter your name: ")
-
Show total amount and ask for payment
print(f"Total to pay: Rp{total}")
paid = int(input("Enter amount paid: "))
if paid >= total:
print("✅ Payment accepted!") -
Show “Preparing Order” with a 1-minute timer
Usetime.sleep()to simulate waiting.print("⏳ Preparing your order...")
for i in range(5):
time.sleep(12) # 5 × 12 sec = 60 sec
print("...", i+1*12, "seconds") -
After timer, show “Order Ready!” and
“Delivering...”
print(f"🍱 {name}, your order is ready!")
time.sleep(3)
print("🚗 Delivering your order...") -
Ask for delivery verification
Confirm that the order is received.done = input("Did you receive your order? (yes/no): ")
if done.lower() == "yes":
print("🎉 Thank you for ordering from Python Restaurant!")
💪 Extra Challenge:
import
random
def foodOrder():
points = 0
print("🎯 Welcome to the Math Quiz!")
print("Answer the addition problems correctly to earn points.")
print("Get 10 points to win the game!\n")
while points < 10:
print(f"Your points: {points}")
# Generate random numbers
num1 = random.randint(1, 100)
num2 = random.randint(1, 100)
# Ask question
answer = input(f"{num1} + {num2} = ? Your answer: ")
# Validate answer
if answer.isdigit() and int(answer) == num1 + num2:
points += 1
print("✅ Correct! You earned 1 point.\n")
else:
print(f"❌ Wrong! The correct answer was {num1 + num2}.\n")
print("🎉 Congrats! You reached 10 points!")
print(f"🏆 Your final score is: {points}")
# Start the quiz
foodOrder()
def foodOrder():
points = 0
print("🎯 Welcome to the Math Quiz!")
print("Answer the addition problems correctly to earn points.")
print("Get 10 points to win the game!\n")
while points < 10:
print(f"Your points: {points}")
# Generate random numbers
num1 = random.randint(1, 100)
num2 = random.randint(1, 100)
# Ask question
answer = input(f"{num1} + {num2} = ? Your answer: ")
# Validate answer
if answer.isdigit() and int(answer) == num1 + num2:
points += 1
print("✅ Correct! You earned 1 point.\n")
else:
print(f"❌ Wrong! The correct answer was {num1 + num2}.\n")
print("🎉 Congrats! You reached 10 points!")
print(f"🏆 Your final score is: {points}")
# Start the quiz
foodOrder()