Untitled
unknown
plain_text
3 years ago
982 B
11
Indexable
#exe_8_Create a function to calculate the total value of the
#warehouse, i.e., the sum of the value of each
#product (price x available quantity).
def create_warehouse():
warehouse = {}
while True:
name = input("Enter product name (or type 'done' to finish): ")
if name == 'done':
break
quantity = int(input("Enter quantity: "))
price = float(input("Enter price: "))
warehouse[name] = {"quantity": quantity, "price": price}
return warehouse
def calculate_total_value(warehouse):
total_value = 0
for product in warehouse:
price = warehouse[product]['price']
quantity = warehouse[product]['quantity']
product_value = price * quantity
total_value += product_value
return total_value
# Example usage
my_warehouse = create_warehouse()
total_value = calculate_total_value(my_warehouse)
print(f"The total value of the warehouse is: {total_value}")
Editor is loading...