Advertisement
simeonshopov

Orders

Feb 4th, 2020
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  1. products = {}
  2.  
  3. while True:
  4.     product = input().split()
  5.     if 'buy' in product:
  6.         break
  7.  
  8.     item = product[0]
  9.     price = float(product[1])
  10.     quantity = int(product[2])
  11.  
  12.     if item not in products:
  13.         products[item] = [price, quantity]
  14.     else:
  15.         if price != products[item][0]:
  16.             products[item][0] = price
  17.         products[item][1] += quantity
  18.  
  19.  
  20. [print(f'{x} -> {(y[0] * y[1]):.2f}') for (x, y) in products.items()]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement