Advertisement
pacho_the_python

Untitled

Dec 3rd, 2023
573
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.45 KB | None | 0 0
  1. areas_with_animals = {}
  2. while True:
  3.     command = input()
  4.     if command == "EndDay":
  5.         break
  6.     instructions = command.split(": ")
  7.     action = instructions[0]
  8.     if action == "Add":
  9.         tokens = instructions[1].split("-")
  10.         animal_name, needed_food, area = tokens[0], int(tokens[1]), tokens[2]
  11.         if area not in areas_with_animals.keys():
  12.             areas_with_animals[area] = {}
  13.         if animal_name not in areas_with_animals[area]:
  14.             areas_with_animals[area][animal_name] = needed_food
  15.         else:
  16.             areas_with_animals[area][animal_name] += needed_food
  17.  
  18.     elif action == "Feed":
  19.         tokens = instructions[1].split("-")
  20.         animal_name, food_given = tokens[0], int(tokens[1])
  21.         for area, animals in areas_with_animals.items():
  22.             if animal_name in animals.keys():
  23.                 areas_with_animals[area][animal_name] -= food_given
  24.                 if areas_with_animals[area][animal_name] <= 0:
  25.                     print(f"{animal_name} was successfully fed")
  26.                     del areas_with_animals[area][animal_name]
  27.  
  28. print("Animals:")
  29. for key, value in areas_with_animals.items():
  30.     for animal in value.keys():
  31.         print(f"{animal} -> {areas_with_animals[key][animal]}g")
  32. print("Areas with hungry animals:")
  33. for area, animals in areas_with_animals.items():
  34.     hungry_animals = len(animals)
  35.     if hungry_animals > 0:
  36.         print(f"{area}: {hungry_animals}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement