Advertisement
Osiris1002

Wild Zoo

Apr 2nd, 2024
614
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.28 KB | None | 0 0
  1. zoo = {"Area": {}}
  2. data_input = input()
  3.  
  4. while data_input != "EndDay":
  5.  
  6.     command_, data = data_input.split(": ")
  7.  
  8.     if command_ == "Add":
  9.         animal_name, needed_food_quantity, area = data.split("-")
  10.         zoo[animal_name] = zoo.get(animal_name, 0) + int(needed_food_quantity)
  11.         if area not in zoo["Area"]:
  12.             zoo["Area"][area] = []
  13.         if animal_name not in zoo["Area"][area]:
  14.             zoo["Area"][area].append(animal_name)
  15.  
  16.     elif command_ == "Feed":
  17.         animal_name, needed_food_quantity = data.split("-")
  18.         if animal_name in zoo:
  19.             zoo[animal_name] -= int(needed_food_quantity)
  20.             if zoo[animal_name] <= 0:
  21.                 del zoo[animal_name]
  22.                 for pet_names in zoo["Area"].values():
  23.                     if animal_name in pet_names:
  24.                         pet_names.remove(animal_name)
  25.                         break
  26.                 print(f"{animal_name} was successfully fed")
  27.  
  28.     data_input = input()
  29.  
  30. if zoo:
  31.     print("Animals:")
  32.     [print(f" {name} -> {quantity}g") for name, quantity in zoo.items() if name != "Area"]
  33.  
  34. if zoo["Area"]:
  35.     print("Areas with hungry animals:")
  36.     [print(f" {area_name}: {len(zoo['Area'][area_name])}") for area_name in zoo["Area"] if zoo["Area"][area_name]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement