Advertisement
Guest User

Plant Discovery

a guest
Mar 22nd, 2022
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.32 KB | None | 0 0
  1. n = int(input())
  2. current_plant = input()
  3.  
  4. plants_info = {}
  5.  
  6. # extract plant's data
  7. for current_rotation in range(1, n + 1):
  8.     current_plant = current_plant.split("<->")
  9.     plant = current_plant[0]
  10.     rarity = int(current_plant[1])
  11.  
  12.     plants_info[plant] = [rarity, []]
  13.  
  14.     if current_rotation == n:
  15.         break
  16.  
  17.     current_plant = input()
  18.  
  19. # Commands
  20. command = input()
  21.  
  22. # index[0] - rarity
  23. # index[1] - rating
  24. # index[2] - count
  25.  
  26. while not command == "Exhibition":
  27.     args = ' '.join(command.split(" - ")).split()
  28.     args = ' '.join(args).split()
  29.     command_cmd = args[0]
  30.     plant_name = args[1]
  31.  
  32.     if plant_name not in plants_info:
  33.         print(f"error")
  34.         break
  35.  
  36.     if command_cmd == "Rate:":
  37.         rating = int(args[2])
  38.         plants_info[plant_name][1].append(rating)
  39.  
  40.     elif command_cmd == "Update:":
  41.         new_rarity = int(args[2])
  42.         plants_info[plant_name][0] = new_rarity
  43.  
  44.     elif command_cmd == "Reset:":
  45.         plants_info[plant_name][1] = []
  46.  
  47.     command = input()
  48.  
  49.  
  50.  
  51. print(f"Plants for the exhibition:")
  52.  
  53. for el in plants_info.items():
  54.     if not el[1][1]:
  55.         # means if el[1][1] is empty list
  56.         average = 0
  57.     else:
  58.         average = sum(el[1][1]) / len(el[1][1])
  59.  
  60.     print(f"- {el[0]}; Rarity: {el[1][0]}; Rating: {average:.2f}")
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement