Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- def accommodate_new_pets(*args):
- capacity = args[0]
- max_weight_limit = args[1]
- accommodated_pets = 0
- accommodation = {}
- for pet_type, pet_weight in args[2:]:
- if capacity and pet_weight <= max_weight_limit:
- capacity -= 1
- accommodated_pets += 1
- if pet_type not in accommodation:
- accommodation[pet_type] = 1
- else:
- accommodation[pet_type] += 1
- elif capacity == 0:
- break
- elif pet_weight > max_weight_limit:
- accommodated_pets += 1
- continue
- result = ''
- if accommodated_pets == len(args[2:]):
- result += f"All pets are accommodated! Available capacity: {capacity}."
- elif capacity == 0:
- result += "You did not manage to accommodate all pets!"
- if accommodation:
- sorted_accommodation = sorted(accommodation.items(), key=lambda x: x[0])
- result += "\nAccommodated pets:"
- for pet_type, number in sorted_accommodation:
- result += f"\n{pet_type}: {number}"
- return result
Add Comment
Please, Sign In to add comment