DEV Community

Discussion on: Daily Challenge #170 - Pokemon Damage Calculator

Collapse
 
kerldev profile image
Kyle Jones • Edited

As there's no mention of the value, I set the base damage to 50 in each scenario.

Code

def compare_attack_types(first_type, second_type):
    if first_type == "fire":
        if second_type == "grass":
            return 2
        if second_type == "water":
            return 0.5
    if first_type == "grass":
        if second_type == "fire":
            return 0.5
        if second_type == "water":
            return 2
    if first_type == "electric":
        if second_type == "water":
            return 2
    if first_type == "water":
        if second_type == "fire":
            return 2
        if second_type == "grass":
            return 0.5
    return 1

def calculate_damage(base_damage, own_type, opponent_type, attack, defense):
    return base_damage * (attack / defense) * compare_attack_types(own_type, opponent_type)

print(calculate_damage(50, "grass", "electric", 57, 19))
print(calculate_damage(50, "grass", "water", 40, 40))
print(calculate_damage(50, "grass", "fire", 35, 5))
print(calculate_damage(50, "fire", "electric", 10, 2))

Results

150
100
175
250