kiril_1914

Task_Orders_Dic_Compr

Mar 12th, 2022
952
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1. def orders():
  2.     dictionary_value = {}
  3.     dictionary_quantity = {}
  4.  
  5.     while True:
  6.         command = input().split(" ")
  7.         if command[0] == "buy":
  8.             break
  9.  
  10.  
  11.         index_one = str(command[0])
  12.         index_two = float(command[1])            # Price
  13.         index_three = int(command[2])
  14.  
  15.         if index_one not in dictionary_quantity.keys():
  16.             dictionary_quantity[index_one] = index_three
  17.         else:
  18.             dictionary_quantity[index_one] += index_three
  19.  
  20.         if index_one not in dictionary_value.keys():
  21.             dictionary_value[index_one] = index_two
  22.  
  23.         if index_two not in dictionary_value.values():
  24.             dictionary_value[index_one] = index_two
  25.  
  26.     result = {k: dictionary_value[k] * dictionary_quantity[k] for k in dictionary_value}
  27.  
  28.     for key,value in result.items():
  29.         print(f"{key} -> {value:.2f}")
  30.  
  31. orders()
Advertisement
Add Comment
Please, Sign In to add comment