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