Advertisement
KNenov96

Untitled

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