Advertisement
horozov86

Orders

Mar 20th, 2023
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. dictionary_price = {}
  2. dictionary_quantity = {}
  3.  
  4. while True:
  5.     line = input()
  6.     if line == "buy":
  7.         break
  8.     line_split = line.split()
  9.     product = line_split[0]
  10.     price = float(line_split[1])
  11.     quantity = int(line_split[2])
  12.  
  13.     if product not in dictionary_price: # Ако продуктът НЕ Е в първия или във втория речник!!!
  14.         dictionary_price[product] = price # Добавяме единичната цена към речника за цените
  15.         dictionary_quantity[product] = quantity # Добавяме количеството къ, речника за количеството
  16.  
  17.     else:
  18.         dictionary_price[product] = price # Обновява се цената
  19.         dictionary_quantity[product] += quantity
  20.  
  21. for product in dictionary_price:
  22.     price = dictionary_price[product]
  23.     quantity = dictionary_quantity[product]
  24.     total_price = price * quantity
  25.  
  26.     print(f"{product} -> {total_price:.2f}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement