Advertisement
go6odn28

4-nether_realms

Mar 27th, 2024
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.35 KB | None | 0 0
  1. import re
  2.  
  3.  
  4. def calculate_health(demons_list):
  5.     demons_data_ = {}
  6.     health_pattern = r'[^\d\+\-\*\/\.\s]'
  7.     for demon in demons_list:
  8.         health = 0
  9.         matches = re.findall(health_pattern, demon)
  10.         for char in matches:
  11.             health += ord(char)
  12.         demons_data_[demon] = []
  13.         demons_data_[demon].append(health)
  14.     return demons_data_
  15.  
  16.  
  17. def calculate_damage(demons_data_, demons_list):
  18.     damage_pattern = r"\-*\d+(\.\d+)*"
  19.     for demon in demons_list:
  20.         damage_match = re.finditer(damage_pattern, demon)
  21.         damage = sum([float(x.group()) for x in damage_match])
  22.         for ch in demon:
  23.             if ch == '*':
  24.                 damage *= 2
  25.             elif ch == '/':
  26.                 damage /= 2
  27.  
  28.         demons_data_[demon].append(damage)
  29.     return demons_data_
  30.  
  31.  
  32. def print_result(demons_data_):
  33.     result = ''
  34.     for demon_name, info in demons_data_.items():
  35.         demon_health, demon_damage = info[0], info[1]
  36.         result += f"{demon_name} - {demon_health} health, {demon_damage:.2f} damage\n"
  37.  
  38.     return print(result)
  39.  
  40.  
  41. def main():
  42.     input_data = sorted([x.strip() for x in input().split(",")])
  43.     demons_data = calculate_health(input_data)
  44.     demons_data = calculate_damage(demons_data, input_data)
  45.     print_result(demons_data)
  46.  
  47.  
  48. if __name__ == '__main__':
  49.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement