Advertisement
KNenov96

Untitled

Nov 28th, 2022
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.36 KB | None | 0 0
  1. number_plants = int(input())
  2. plant_dictionary = {}
  3. plant_rating = {}
  4.  
  5. for plant in range(number_plants):
  6.     plant_name, rarity = input().split("<->")
  7.     plant_dictionary[plant_name] = int(rarity)
  8.  
  9. while True:
  10.     command = input().split(": ")
  11.     if command[0] == "Exhibition":
  12.         break
  13.  
  14.     plant = command[1].split(" - ")[0]
  15.     if plant not in plant_dictionary:
  16.         print("error")
  17.  
  18.     elif command[0] == "Rate":
  19.         rating = command[1].split(" - ")[1]
  20.         if plant not in plant_rating.keys():
  21.             plant_rating[plant] = [int(rating)]
  22.         else:
  23.             plant_rating[plant].append(int(rating))
  24.  
  25.     elif command[0] == "Update":
  26.         new_rarity = command[1].split(" - ")[1]
  27.         plant_dictionary[plant] = int(new_rarity)
  28.  
  29.     elif command[0] == "Reset":
  30.         plant_rating[plant] = []
  31.  
  32. for key in plant_rating.keys():
  33.     if len(plant_rating[key]) > 0:
  34.         plant_rating[key] = [sum(plant_rating[key]) / len(plant_rating[key])]
  35.     else:
  36.         plant_rating[key] = [0]
  37.  
  38. for key in plant_rating.keys():
  39.     plant_rating[key] = [str(f"{i:.2f}") for i in plant_rating[key]]
  40.  
  41. print("Plants for the exhibition:")
  42. for key in plant_dictionary.keys():
  43.     if key not in plant_rating:
  44.         plant_rating[key] = ["0.00"]
  45.     print(f"- {key}; Rarity: {plant_dictionary[key]}; Rating: {''.join(plant_rating[key])}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement