I have just become a member and working through the exercises. I’m up to Python/Currency Exchange Task 6. My code works when I try it in Jupiter Notebook on both examples, however it doesn’t pass me in Exercism editor?
My finished code for Task 6 is:
def exchangeable_value(budget, exchange_rate, spread, denomination):
"""
:param budget: float - the amount of your money you are planning to exchange.
:param exchange_rate: float - the unit value of the foreign currency.
:param spread: int - percentage that is taken as an exchange fee.
:param denomination: int - the value of a single bill.
:return: int - maximum value you can get.
"""
spread = spread / 100
exchange_rate = exchange_rate + spread
budget = int(budget / exchange_rate)
return int((budget // denomination) * denomination)
As keiraville has mentioned, we run quite a few more tests on the website, and they all need to pass before the exercise can be marked complete. Your code is failing one of them most likely due to rounding errors or some input you may not have thought of.
To help us troubleshoot your code, the best thing to do is to paste your whole solution into a code block along with any failed tests and errors, so we can work throught it. Images aren’t always readable and they force troubleshooters to retype code - which can lead to errors.
Edited to add: Sorry - I didn’t register that you added a code block, but it broke. I’ve edited your post to correct it.
Because this is a concept exercise, we don’t show the full test suite on the website — only the failed cases. However, when working locally, you can grab the test suite from github and run the tests locally using pytest.
Here are some tips for working locally and here is a quick summary for using Pytest in Jupyter, although I strongly recommend that you use a different IDE, since Jupyter makes things much more difficult to execute and to troubleshoot.
Here are directions for downloading and using our CLI tool to work with exercises locally.
Hi BethanyG
Thank you for your reply however I have worked out the issue.
I was adding the difference of the spread as a calculation, however it should be the percentage of the spread added to the rate. exchange_rate * (1 + spread) and not just exchange_rate + spread.
Thank you for your reply, much appreciated, however I have solved this issue -
I was adding the difference of the spread as a calculation, however it should be the percentage of the spread added to the rate. exchange_rate * (1 + spread) and not just exchange_rate + spread.
If you’re not already, you also might find it helpful/easier to use the CLI to download the exercises and run the tests locally, rather than copying/pasting into the online editor.