Advertisement
viligen

plant_discovery

Dec 3rd, 2021
778
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.19 KB | None | 0 0
  1. n = int(input())
  2.  
  3. plants = {}
  4.  
  5. for _ in range(n):
  6.     plant, rarity = input().split("<->")
  7.     rating = []
  8.     rarity = int(rarity)
  9.     plants[plant] = [rarity, rating]
  10.  
  11. while True:
  12.     command = input().split()
  13.  
  14.     if "Exhibition" in command[0]:
  15.         break
  16.     plant = command[1]
  17.     if "Rate" in command[0]:
  18.         rating = int(command[3])
  19.         if plant not in plants:
  20.             print("error")
  21.         else:
  22.             plants[plant][1].append(rating)
  23.     elif "Update" in command[0]:
  24.         new_rarity = int(command[3])
  25.         if plant not in plants:
  26.             print("error")
  27.         else:
  28.             plants[plant][0] = new_rarity
  29.     elif "Reset" in command[0]:
  30.         if plant not in plants:
  31.             print("error")
  32.         else:
  33.             plants[plant][1] = []
  34. for k, v in plants.items():
  35.     if len(v[1]) > 0:
  36.         v[1] = sum(v[1])/len(v[1])
  37.     else:
  38.         v[1] = 0
  39. sorted_plants = sorted(plants.items(), key=lambda kvp: (-kvp[1][0], -kvp[1][1]))
  40. print("Plants for the exhibition:")
  41. for plant_, data in sorted_plants:
  42.     rarity_ = data[0]
  43.     average_rating = data[1]
  44.     print(f"- {plant_}; Rarity: {rarity_}; Rating: {average_rating:.2f}")
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement