Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- command = input()
- successfully_fed = []
- unfed_animals_food = []
- areas = []
- while command != 'Last Info':
- command = command.split(':')
- animal_name = command[1]
- animal_food = int(command[2])
- animal_area = command[3]
- if command[0] == 'Add':
- if len([x for x in unfed_animals_food if x[0] == animal_name]) > 0:
- index = unfed_animals_food.index([x for x in unfed_animals_food if x[0] == animal_name][0])
- unfed_animals_food[index][1] += int(animal_food)
- else:
- unfed_animals_food.append([animal_name, animal_food])
- areas.append(animal_area)
- elif command[0] == 'Feed':
- if len([x for x in unfed_animals_food if x[0] == animal_name]) > 0:
- index = unfed_animals_food.index([x for x in unfed_animals_food if x[0] == animal_name][0])
- unfed_animals_food[index][1] -= int(animal_food)
- if unfed_animals_food[index][1] <= 0:
- unfed_animals_food.remove(unfed_animals_food[index])
- areas.remove(areas[index])
- print(f'{animal_name} was successfully fed')
- command = input()
- print('Animals:')
- unfed_animals_food = sorted(unfed_animals_food, key=lambda x: (-x[1], x[0]))
- for i in unfed_animals_food:
- print(f'{i[0]} -> {i[1]}')
- print('Areas with hungry animals:')
- areas1=[]
- for j in range(len(areas)):
- kk=areas.count(areas[j])
- if areas[j][0] not in areas1:
- areas1.append([areas[j], kk])
- print(areas1)
- print(f'{areas[j]} : {kk}')
- print(areas1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement