Advertisement
Dimitar182

Hero Recruitment

Apr 2nd, 2023
584
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.11 KB | None | 0 0
  1. heroes = {}
  2.  
  3. while True:
  4.     command = input().split()
  5.     if command[0] == "End":
  6.         break
  7.  
  8.     if command[0] == "Enroll":
  9.         hero_name = command[1]
  10.         if hero_name not in heroes:
  11.             heroes[hero_name] = []
  12.         else:
  13.             print(f"{hero_name} is already enrolled.")
  14.  
  15.     elif command[0] == "Learn":
  16.         hero_name, spell_name = command[1], command[2]
  17.         if hero_name not in heroes:
  18.             print(f"{hero_name} doesn't exist.")
  19.         elif spell_name in heroes[hero_name]:
  20.             print(f"{hero_name} has already learnt {spell_name}.")
  21.         else:
  22.             heroes[hero_name].append(spell_name)
  23.  
  24.     elif command[0] == "Unlearn":
  25.         hero_name, spell_name = command[1], command[2]
  26.         if hero_name not in heroes:
  27.             print(f"{hero_name} doesn't exist.")
  28.         elif spell_name not in heroes[hero_name]:
  29.             print(f"{hero_name} doesn't know {spell_name}.")
  30.         else:
  31.             heroes[hero_name].remove(spell_name)
  32.  
  33. print("Heroes:")
  34. for hero, spells in sorted(heroes.items()):
  35.     print(f"== {hero}: {', '.join(spells)}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement