DEV Community

Discussion on: Daily Challenge #61 - Evolution Rate

Collapse
 
colorfusion profile image
Melvin Yeo

I wrote it in Python, kept it as short as possible while maintaining clarity. 😎

def getEvolutionRateMessage(before, after):
    if before == after:
        return "No evolution"

    polarity = "positive" if after > before else "negative"
    evo_rate = round(abs(after - before) * 100 / (before if before != 0 and after != 0 else 1))

    return f"A {polarity} evolution of {evo_rate}%"
Collapse
 
aminnairi profile image
Amin

Neat! I like what they did with this new string interpolation thing in Python.

I Didn't know it was called a polarity. Learning new things every day. Yay!