import random

def aimed(player_attributes, enemy_attributes):
	if player_attributes['endurance'] < enemy_attributes['endurance'] // 10 * 10:
		player_attributes['endurance'] += 1
	else:
		underleveled_attrs = list(attr for attr in player_attributes if player_attributes[attr] <= enemy_attributes[attr] // 2)
		if underleveled_attrs:
			player_attributes[random.choice(underleveled_attrs)] += 1
		else:
			worst_enemy_attr_value = min(enemy_attributes.values())
			worst_enemy_attrs = list(attr for attr in enemy_attributes if enemy_attributes[attr] == worst_enemy_attr_value)
			player_attributes[random.choice(worst_enemy_attrs)] += 1

	return player_attributes

def stats_dict(endurance, strength, agility, speed):
	return {'endurance': endurance, 'strength': strength, 'agility': agility, 'speed': speed}

def stats_to_string(stats):
	return "(END {endurance}, STR {strength}, AGI {agility}, SPD {speed})".format(**stats)

def test(player_endurance, player_strength, player_agility, player_speed,
         enemy_endurance, enemy_strength, enemy_agility, enemy_speed):
	player       = stats_dict(player_endurance, player_strength, player_agility, player_speed)
	enemy        = stats_dict(enemy_endurance, enemy_strength, enemy_agility, enemy_speed)
	aimed_result = aimed(player.copy(), enemy)
	print("aim {0} to {1}: {2}".format(stats_to_string(player), stats_to_string(enemy), stats_to_string(aimed_result)))

test(99, 3, 3, 3, 99, 9, 9, 9)
test(99, 8, 8, 8, 99, 20, 20, 20)
test(99, 3, 3, 3, 99, 4, 4, 4)
test(99, 8, 8, 8, 99, 9, 9, 9)