Advertisement
bl00dt3ars

03. Plant Discovery

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