Advertisement
Guest User

Untitled

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