Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n = int(input())
- plants = {}
- for _ in range(n):
- plant, rarity = input().split("<->")
- rating = []
- rarity = int(rarity)
- plants[plant] = [rarity, rating]
- while True:
- command = input().split()
- if "Exhibition" in command[0]:
- break
- plant = command[1]
- if "Rate" in command[0]:
- rating = int(command[3])
- if plant not in plants:
- print("error")
- else:
- plants[plant][1].append(rating)
- elif "Update" in command[0]:
- new_rarity = int(command[3])
- if plant not in plants:
- print("error")
- else:
- plants[plant][0] = new_rarity
- elif "Reset" in command[0]:
- if plant not in plants:
- print("error")
- else:
- plants[plant][1] = []
- for k, v in plants.items():
- if len(v[1]) > 0:
- v[1] = sum(v[1])/len(v[1])
- else:
- v[1] = 0
- sorted_plants = sorted(plants.items(), key=lambda kvp: (-kvp[1][0], -kvp[1][1]))
- print("Plants for the exhibition:")
- for plant_, data in sorted_plants:
- rarity_ = data[0]
- average_rating = data[1]
- print(f"- {plant_}; Rarity: {rarity_}; Rating: {average_rating:.2f}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement