lussi_h

Untitled

Oct 15th, 2025
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.10 KB | None | 0 0
  1. def accommodate_new_pets(*args):
  2.     capacity = args[0]
  3.     max_weight_limit = args[1]
  4.     accommodated_pets = 0
  5.  
  6.     accommodation = {}
  7.     for pet_type, pet_weight in args[2:]:
  8.         if capacity and pet_weight <= max_weight_limit:
  9.             capacity -= 1
  10.             accommodated_pets += 1
  11.             if pet_type not in accommodation:
  12.                 accommodation[pet_type] = 1
  13.             else:
  14.                 accommodation[pet_type] += 1
  15.         elif capacity == 0:
  16.             break
  17.         elif pet_weight > max_weight_limit:
  18.             accommodated_pets += 1
  19.             continue
  20.  
  21.     result = ''
  22.  
  23.     if accommodated_pets == len(args[2:]):
  24.         result += f"All pets are accommodated! Available capacity: {capacity}."
  25.     elif capacity == 0:
  26.         result += "You did not manage to accommodate all pets!"
  27.  
  28.     if accommodation:
  29.         sorted_accommodation = sorted(accommodation.items(), key=lambda x: x[0])
  30.         result += "\nAccommodated pets:"
  31.         for pet_type, number in sorted_accommodation:
  32.             result += f"\n{pet_type}: {number}"
  33.  
  34.     return result
Tags: 3_pets_hotel
Add Comment
Please, Sign In to add comment