Skip to content

Commit

Permalink
Changes in the orders
Browse files Browse the repository at this point in the history
  • Loading branch information
endarkX committed May 16, 2024
1 parent 5ba916b commit fb3c805
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 29 deletions.
15 changes: 7 additions & 8 deletions café-ordering/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ def add_drink_to_order(order, drinks, drink_name, size, customizations=None):
"""Adds a drink to the order, considering size and customizations."""
for drink in drinks:
if drink["name"].lower() == drink_name.lower() and drink["size"] == size:
drink_to_add = drink.copy() # Create a copy to avoid modifying original data
drink_to_add = drink.copy()
if customizations:
drink_to_add["customizations"] = customizations
order.append(drink_to_add)
print(f"{drink_name} ({size}) added to your order!")
return # Exit after finding and adding the drink
return

print(f"Sorry, we don't have '{drink_name}' in size '{size}'.")

Expand All @@ -19,8 +19,7 @@ def add_pastry_to_order(order, pastries, pastry_name, quantity=1):
pastry_to_add["quantity"] = quantity
order.append(pastry_to_add)
print(f"{quantity} {pastry_name} added to your order!")
return # Exit after finding and adding the pastry

return
print(f"Sorry, we don't have '{pastry_name}' available.")

def remove_item_from_order(order, item_name):
Expand All @@ -29,7 +28,7 @@ def remove_item_from_order(order, item_name):
if item["name"].lower() == item_name.lower():
removed_item = order.pop(i)
print(f"{removed_item['name']} removed from your order.")
return # Exit after finding and removing the item
return

print(f"{item_name} not found in your order.")

Expand All @@ -43,8 +42,8 @@ def display_order(order):
total_cost = 0
for item in order:
name = item["name"]
size = item.get("size", "") # Print size only for drinks
quantity = item.get("quantity", 1) # Print quantity only for pastries
size = item.get("size", "")
quantity = item.get("quantity", 1)
price = item["price"]
customizations = item.get("customizations", None)

Expand All @@ -58,7 +57,7 @@ def calculate_total_cost(order):
total_cost = 0
for item in order:
price = item["price"]
quantity = item.get("quantity", 1) # Consider quantity for pastries
quantity = item.get("quantity", 1)
total_cost += price * quantity
return total_cost

11 changes: 3 additions & 8 deletions café-ordering/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,20 @@ def take_order(drinks, pastries):
choice = input("Enter 'd' to order drinks, 'p' for pastries, 'v' to view order, 'r' to remove items, 'q' to quit: ").lower()

if choice == 'd':
# Implement logic to add drinks to the order (consider size, customizations)
pass
elif choice == 'p':
# Implement logic to add pastries to the order (consider quantity)
elif choice == 'p':
pass
elif choice == 'v':
# Display the current order details (name, size, price, quantity, customizations)
pass
elif choice == 'r':
# Implement logic to remove items from the order
pass
elif choice == 'q':
break
else:
print("Invalid input. Please enter a valid option.")

# Calculate the total order cost

total_cost = 0
# Implement logic to iterate through the order and calculate total cost


print(f"\nYour order total is: ${total_cost:.2f}")

Expand Down
24 changes: 11 additions & 13 deletions café-ordering/schema.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
# Define data structures for menu items (drinks and pastries)
drink = {
"name": str, # Name of the drink
"size": str, # Size (e.g., Small, Medium, Large)
"price": float, # Price of the drink
"name": str,
"size": str,
"price": float,
}

pastry = {
"name": str, # Name of the pastry
"price": float, # Price of the pastry
}
"name": str,
"price": float, }


# Define data structure for an order item (combines drink or pastry with its quantity and customizations)
order_item = {
"name": str, # Name of the drink or pastry
"size": str, # Size (applicable to drinks only)
"price": float, # Price of the item
"quantity": int, # Quantity of the item (default 1)
"customizations": str | None, # Optional customizations (applicable to drinks)
"name": str,
"size": str,
"price": float,
"quantity": int,
"customizations": str | None,
}

0 comments on commit fb3c805

Please sign in to comment.