Advertisement
viligen

heroes_of_code_and_logic

Nov 23rd, 2021
807
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.84 KB | None | 0 0
  1. numbers = int(input())
  2. heroes_data = {}
  3.  
  4. for _ in range(numbers):
  5.     hero_name, hp, mp = input().split()
  6.     hp = int(hp)
  7.     mp = int(mp)
  8.     heroes_data[hero_name] = [hp, mp]
  9.  
  10. while True:
  11.     command = input().split(" - ")
  12.     if "End" == command[0]:
  13.         break
  14.     elif "CastSpell" == command[0]:
  15.         hero, mp, spell = command[1:]
  16.         if heroes_data[hero][1] >= int(mp):
  17.             heroes_data[hero][1] -= int(mp)
  18.             print(f"{hero} has successfully cast {spell} and now has {heroes_data[hero][1]} MP!")
  19.         else:
  20.             print(f"{hero} does not have enough MP to cast {spell}!")
  21.     elif "TakeDamage" == command[0]:
  22.         hero, damage, attacker = command[1:]
  23.         if heroes_data[hero][0] - int(damage) > 0:
  24.             heroes_data[hero][0] -= int(damage)
  25.             print(f"{hero} was hit for {damage} HP by {attacker} and now has {heroes_data[hero][0]} HP left!")
  26.         else:
  27.             print(f"{hero} has been killed by {attacker}!")
  28.             del heroes_data[hero]
  29.     elif "Recharge" == command[0]:
  30.         hero, amount = command[1:]
  31.         if heroes_data[hero][1] + int(amount) >= 200:
  32.             amount = 200 - heroes_data[hero][1]
  33.             heroes_data[hero][1] += amount
  34.         else:
  35.             heroes_data[hero][1] += int(amount)
  36.         print(f"{hero} recharged for {amount} MP!")
  37.     elif "Heal" == command[0]:
  38.         hero, amount = command[1:]
  39.         if heroes_data[hero][0] + int(amount) >= 100:
  40.             amount = 100 - heroes_data[hero][0]
  41.             heroes_data[hero][0] += amount
  42.         else:
  43.             heroes_data[hero][0] += int(amount)
  44.         print(f"{hero} healed for {amount} HP!")
  45.  
  46. sorted_heroes = sorted(heroes_data.items(), key=lambda kvp: (-kvp[1][0], kvp[0]))
  47. for hero, data in sorted_heroes:
  48.     print(f"""{hero}
  49.  HP: {data[0]}
  50.  MP: {data[1]}""")
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement