Advertisement
George_Ivanov05

pro

Aug 6th, 2021
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.42 KB | None | 0 0
  1. n = int(input())
  2.  
  3. my_dict = {}
  4.  
  5. for i in range(n):
  6.     heroes = input().split()
  7.     hero_name = heroes[0]
  8.     if int(heroes[1]) <= 100 and int(heroes[2]) <= 200:
  9.         hero_HP = int(heroes[1])
  10.         hero_MP = int(heroes[2])
  11.         my_dict[hero_name] = {"hp": hero_HP, "mp": hero_MP}
  12.  
  13. command = input().split(" - ")
  14.  
  15. while not command[0] == "End":
  16.     if command[0] == "CastSpell":
  17.         hero_name = command[1]
  18.         mp_needed = int(command[2])
  19.         spell_name = command[3]
  20.         if mp_needed <= my_dict[hero_name]["mp"]:
  21.             mp_left = my_dict[hero_name]["mp"] - mp_needed
  22.             my_dict[hero_name]["mp"] = mp_left
  23.             print(f"{hero_name} has successfully cast {spell_name} and now has {mp_left} MP!")
  24.         else:
  25.             print(f"{hero_name} does not have enough MP to cast {spell_name}!")
  26.     elif command[0] == "TakeDamage":
  27.         hero_name = command[1]
  28.         damage = int(command[2])
  29.         attacker = command[3]
  30.         if my_dict[hero_name]["hp"] - damage > 0:
  31.             hp_left = my_dict[hero_name]["hp"] - damage
  32.             my_dict[hero_name]["hp"] = hp_left
  33.             print(f"{hero_name} was hit for {damage} HP by {attacker} and now has {hp_left} HP left!")
  34.         else:
  35.             print(f"{hero_name} has been killed by {attacker}!")
  36.             my_dict.pop(hero_name)
  37.     elif command[0] == "Recharge":
  38.         hero_name = command[1]
  39.         amount = int(command[2])
  40.         if my_dict[hero_name]["mp"] + amount <= 200:
  41.             my_dict[hero_name]["mp"] += amount
  42.             print(f"{hero_name} recharged for {amount} MP!")
  43.         else:
  44.             recharged_health = 200 - my_dict[hero_name]["mp"]
  45.             print(f"{hero_name} recharged for {recharged_health} MP!")
  46.             my_dict[hero_name]["mp"] = 200
  47.     elif command[0] == "Heal":
  48.         hero_name = command[1]
  49.         amount = int(command[2])
  50.         if my_dict[hero_name]["hp"] + amount <= 100:
  51.             my_dict[hero_name]["hp"] += amount
  52.             print(f"{hero_name} healed for {amount} HP!")
  53.         else:
  54.             recharged_health = 100 - my_dict[hero_name]["hp"]
  55.             print(f"{hero_name} healed for {recharged_health} HP!")
  56.             my_dict[hero_name]["hp"] = 100
  57.     command = input().split(" - ")
  58.  
  59. for key, value in sorted(my_dict.items(), key=lambda x: (-x[1]["hp"], x[0])):
  60.     print(key)
  61.     print(f"  HP: {value['hp']}")
  62.     print(f"  MP: {value['mp']}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement