Advertisement
pacho_the_python

Untitled

Mar 8th, 2022
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.84 KB | None | 0 0
  1. num = int(input())
  2.  
  3. flowers_dict = {}
  4.  
  5. for i in range(num):
  6.     data = input().split("<->")
  7.     plant = data[0]
  8.     rarity = int(data[1])
  9.     if plant not in flowers_dict:
  10.         flowers_dict[plant] = [rarity]
  11.  
  12. stat = input().split(": ")
  13.  
  14. while True:
  15.     command = stat[0]
  16.     if command == "Exhibition":
  17.         break
  18.  
  19.     if command == "Rate":
  20.         rating_data = stat[1].split(" - ")
  21.         flower = rating_data[0]
  22.         rating = int(rating_data[1])
  23.         if flower in flowers_dict:
  24.             flowers_dict[flower].append(rating)
  25.         else:
  26.             print("error")
  27.  
  28.     elif command == "Update":
  29.         rarity_data = stat[1].split(" - ")
  30.         current_flower = rarity_data[0]
  31.         new_rarity = int(rarity_data[1])
  32.         if current_flower in flowers_dict:
  33.             flowers_dict[current_flower][0] = new_rarity
  34.         else:
  35.             print("error")
  36.  
  37.     elif command == "Reset":
  38.         reset_flower = stat[1]
  39.         if reset_flower in flowers_dict:
  40.             for i in range(1, len(flowers_dict[reset_flower])):
  41.                 flowers_dict[reset_flower].pop(1)
  42.         else:
  43.             print("error")
  44.  
  45.     stat = input().split(": ")
  46.  
  47. average_stat = {}
  48.  
  49. for i in flowers_dict:
  50.     if len(flowers_dict[i]) == 1:
  51.         average = 0
  52.     else:
  53.         average = (sum(flowers_dict[i]) - flowers_dict[i][0]) / (len(flowers_dict[i]) - 1)
  54.  
  55.     average_stat[i] = average
  56.  
  57. print("Plants for the exhibition:")
  58.  
  59. result = {}
  60.  
  61. for i in flowers_dict:
  62.     result[i] = [flowers_dict[i][0], average_stat[i]]
  63.  
  64. sorted_list = []
  65.  
  66. for i in result:
  67.     sorted_list.append(result[i][0])
  68.  
  69. sorted_list.sort()
  70. sorted_list.reverse()
  71.  
  72. for x in sorted_list:
  73.     for y in result:
  74.         if x == result[y][0]:
  75.             print(f"- {y}; Rarity: {result[y][0]}; Rating: {result[y][1]:.2f}")
  76.            
  77.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement