Sichanov

orders

Nov 1st, 2021
1,560
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | None | 0 0
  1. command = input()
  2. products = {}
  3. while not command == 'buy':
  4.     split_command = command.split()
  5.     product = split_command[0]
  6.     price = float(split_command[1])
  7.     quantity = int(split_command[2])
  8.     if product not in products:
  9.         products[product] = [price, quantity]
  10.     else:
  11.         if products[product][0] != price:
  12.             products[product][0] = price
  13.         products[product][1] += quantity
  14.     command = input()
  15.  
  16. print('\n'.join(f'{key} -> {value[0] * value[1]:.2f}' for key, value in products.items()))
  17.  
Advertisement
Add Comment
Please, Sign In to add comment