Win Percentage

Hello,

In this particular exercise we are asked to find the win percentage when we are given two parameters “wins” and “losses”.
The mathematical solution would be (win / wins + losses) * 100%.
Now here’s my question, when I used the return as (win / wins + losses) * 100, with the value (5,5) the result was 600.0, when it was supposed to be 50.
Why did I get this ?

When I looked in the solution it was basically the same thing they did but with more steps. They created different variables to first add wins and losses then multiply by 100 separately. Isn’t this the same thing?

https://www.codecademy.com/courses/learn-python-3/lessons/python-functions-syntax-cc/exercises/win-percentage

(5 / 5 + 5) * 100
(1.0 + 5) * 100
6.0 * 100
600.0
1 Like

This translates to, 1 + losses due to operator precedence. Multiplication over addition. To change the order of operations, group the additive terms…

wins / (wins + losses)
2 Likes