Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- places = {}
- animals = {}
- while True:
- command = input()
- if command == "EndDay":
- break
- data = command.split(": ")
- action = data[0]
- if action == "Add":
- name, food, area = data[1].split('-')
- food = int(food)
- if name not in animals:
- animals[name] = {'food': food, 'area': area}
- else:
- animals[name]['food'] += food
- if area not in places:
- places[area] = []
- if name not in places[area]:
- places[area].append(name)
- elif action == "Feed":
- name, food = data[1].split('-')
- food = int(food)
- if name in animals:
- animals[name]['food'] -= food
- if animals[name]['food'] <= 0:
- animals.pop(name)
- print(f"{name} was successfully fed!")
- for area in places:
- if name in places[area]:
- places[area] = [el for el in places[area] if not el == name]
- places = {area: name for area, name in places.items() if not len(name) == 0}
- # for name, area in animals.items():
- # new = area['area']
- # if new not in places:
- # places[new] = [name]
- # else:
- # places[new].append(name)
- animals = sorted(animals.items(), key=lambda x: (-x[1]['food'], x[0]))
- places = sorted(places.items(), key=lambda x: (-len(x[1]), x[0]))
- print(f"Animals:")
- for name, food in animals:
- print(f" {name} -> {food['food']}g")
- print("Areas with hungry animals:")
- for area, animals in places:
- print(f" {area}: {len(animals)}")
Add Comment
Please, Sign In to add comment