Advertisement
GeorgiLukanov87

05. Dragon Army Dictionaries - More Exercises 100/100

Aug 4th, 2022
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.48 KB | None | 0 0
  1. # 05. Dragon Army Dictionaries - More Exercises 100/100
  2. # https://judge.softuni.org/Contests/Practice/Index/1738#4
  3.  
  4.  
  5. n_dragons = int(input())
  6. my_dragons = {}
  7.  
  8. for _ in range(n_dragons):
  9.     details = input().split()
  10.     color_type = details[0]
  11.     name = details[1]
  12.    
  13.     if not name[0].isupper():
  14.         continue
  15.     damage = details[2]
  16.     if damage == 'null':
  17.         damage = 45
  18.     else:
  19.         damage = int(damage)
  20.     health = details[3]
  21.     if health == 'null':
  22.         health = 250
  23.     else:
  24.         health = int(health)
  25.     armor = details[4]
  26.     if armor == 'null':
  27.         armor = 10
  28.     else:
  29.         armor = int(armor)
  30.  
  31.     if color_type not in my_dragons:
  32.         my_dragons[color_type] = {name: [damage, health, armor]}
  33.     else:
  34.         if name not in my_dragons[color_type]:
  35.             my_dragons[color_type].update({name: [damage, health, armor]})
  36.         else:
  37.             my_dragons[color_type].update({name: [damage, health, armor]})
  38.  
  39. for key, value in my_dragons.items():
  40.     average_sum = [0, 0, 0]
  41.     for dragon, stats in value.items():
  42.         for index, el in enumerate(stats):
  43.             average_sum[index] += el / len(value)
  44.  
  45.     print(key, end="::")
  46.     result = ('/'.join([f"{el:.2f}" for el in average_sum]))
  47.     print(f"({result})")
  48.  
  49.     for dragon1, stats1 in sorted(value.items(), key=lambda x: x[0]):
  50.         result = f"-{dragon1} -> damage: {stats1[0]}, health: {stats1[1]}, armor: {stats1[2]}"
  51.         print(result)
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement