viligen

heroes_of_code_and_logic_2

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