forked from data-bootcamp-v4/lab-python-functions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcat.tx
More file actions
59 lines (50 loc) · 2.09 KB
/
cat.tx
File metadata and controls
59 lines (50 loc) · 2.09 KB
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
ef initialize_inventory(products):
inventory = {}
for product in products:
quantity = int(input(f"Enter the quantity for {product}: "))
inventory[product] = quantity
return inventory
def get_customer_orders(products):
customer_orders = set()
while True:
order = ""
while order not in products:
order = input(f"Enter a product to order (choose from {', '.join(products)}): ")
if order not in products:
print("Invalid product name. Please choose from the available products.")
customer_orders.add(order)
continue_ordering = input("Do you want to add another product? (yes/no): ")
if continue_ordering != 'yes':
break
return customer_orders
def update_inventory(customer_orders, inventory):
for product in customer_orders:
if inventory[product] > 0:
inventory[product] -= 1
else:
print(f"Sorry, {product} is out of stock.")
def calculate_order_statistics(customer_orders, products):
total_products_ordered = len(customer_orders)
percentage_ordered = (total_products_ordered / len(products)) * 100
return total_products_ordered, percentage_ordered
def print_order_statistics(order_statistics):
print("Order Statistics:")
print(f"Total Products Ordered: {order_statistics[0]}")
print(f"Percentage of Products Ordered: {order_statistics[1]:.2f}%")
def print_updated_inventory(inventory):
print("Updated Inventory:")
for product, quantity in inventory.items():
print(f"{product}: {quantity}")
def main():
products = ["t-shirt", "mug", "hat", "book", "keychain"]
inventory = initialize_inventory(products)
customer_orders = get_customer_orders(products)
print("Customer ordered the following products:")
for item in customer_orders:
print(f"- {item}")
update_inventory(customer_orders, inventory)
order_statistics = calculate_order_statistics(customer_orders, products)
print_order_statistics(order_statistics)
print_updated_inventory(inventory)
# Run the program
main()