Advertisement
horozov86

3.Statistics

Mar 2nd, 2023
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. products = {}
  2.  
  3. command = input()
  4.  
  5. while command != "statistics":
  6.     command_split = command.split(": ")
  7.     product = command_split[0]
  8.     quantity = int(command_split[1])
  9.    
  10.     if product not in products:
  11.         products[product] = 0
  12.        
  13.     products[product] += quantity
  14.    
  15.     command = input()
  16.    
  17. print("Products in stock:")
  18. for (product, quantity) in products.items():
  19.  
  20.     print(f"- {product}: {quantity}")
  21.    
  22. print(f"Total Products: {len(products.keys())}")
  23. print(f"Total Quantity: {sum(products.values())}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement