For the Numbers exercise in the Python track, my initial algorithm for calculating task 6 failed. I adjusted it to make it pass, but no matter how I stare at it, it doesn’t seem correct.
For task 6, Calculate Value after Exchange we have budget (the amount we want to convert), an exchange rate, the spread (“The percentage that is taken as an exchange fee.”), then the denomination.
Seems pretty straightforward:
- Calculate the foreign_currency you will receive → budget / exchange rate
- Subtract the exchange fee → foreign_currency * (100 - spread) / 100
- Round down for denomination
However, when I do this it fails. What passes is substituting → foreign_currency * (100 / 100 + spread) for step 2.
But if the spread is 25, then they’re taking 25% of the converted currency before handing it to you. You get 75%. But 100/125 is 80%, not 75%.