Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- command = input().split(':')
- animals = {}
- areas = {}
- while True:
- if command[0] == 'Last Info':
- break
- command_type = command[0]
- animal = command[1]
- food = int(command[2])
- area = command[3]
- if command_type == 'Add':
- if area in areas:
- if animal not in animals:
- areas[area] += 1
- else:
- areas[area] = 1
- if animal in animals:
- animals[animal] += food
- else:
- animals[animal] = food
- elif command_type == 'Feed':
- if animal in animals:
- animals[animal] -= food
- if animals[animal] <= 0:
- print(f'{animal} was successfully fed')
- del animals[animal]
- areas[area] -= 1
- if areas[area] <= 0:
- del areas[area]
- command = input().split(':')
- animals_sorted = sorted(animals, key=animals.get, reverse=True)
- areas_sorted = sorted(areas, key=areas.get, reverse=True)
- print('Animals:')
- for i in animals_sorted:
- print(f'{i} -> {animals[i]}g')
- print('Areas with hungry animals:')
- for i in areas_sorted:
- print(f'{i} : {areas[i]}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement