Advertisement
exDotaPro

battle_manager

Aug 5th, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.25 KB | None | 0 0
  1. people = dict()
  2.  
  3. while True:
  4.     line = input().split(':')
  5.     command = line[0]
  6.  
  7.     if command == 'Results':
  8.         break
  9.  
  10.     if command == 'Add':
  11.         name, health, energy = line[1], int(line[2]), int(line[3])
  12.         if name not in people:
  13.             people[name] = [0, 0]
  14.         people[name][0] += health
  15.         people[name][1] += energy
  16.     elif command == 'Attack':
  17.         attacker, defender, dmg = line[1], line[2], int(line[3])
  18.         if attacker in people and defender in people:
  19.             people[defender][0] -= dmg
  20.             if people[defender][0] <= 0:
  21.                 print(f'{defender} was disqualified!')
  22.                 del people[defender]
  23.             people[attacker][1] -= 1
  24.             if people[attacker][1] <= 0:
  25.                 print(f'{attacker} was disqualified!')
  26.                 del people[attacker]
  27.     elif command == 'Delete':
  28.         name = line[1]
  29.         if name == 'All':
  30.             people.clear()
  31.         elif name in people:
  32.             del people[name]
  33.  
  34. print(f'People count: {len(people)}')
  35. people = {k: v for k, v in sorted(people.items(), key=lambda x: (-x[1][0], x[0]))}
  36. for person, stats in people.items():
  37.     health, energy = stats
  38.     print(f'{person} - {health} - {energy}')
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement