Hello,
I just finished the currency exchange exercise. The exercise itself is straight forward, and the explanations are excellent (seriously!), but I managed to confuse myself, and I spent a bit of time trying to understand why.
It was only after I got the last task wrong that I realized that I had spent the entire exercise assuming that the number_of_bills
thing had to do with the original currency.
In retrospect (a) this is a totally silly assumption, and (b) the instructions clearly state that The total you receive must be divisible by the value of one “bill” or unit. (Emphasis added)
However, I was paying a lot more attention to the code than the instructions, and in the code it says:
def get_number_of_bills(budget, denomination):
"""
:param budget: float - the amount of money you are planning to exchange.
:param denomination: int - the value of a single bill.
:return: int - number of bills after exchanging all your money.
"""
pass
The key bit that I think led me down the garden path was the name budget
and the description the amount of money you are planning to exchange
. To me budget definitely has the flavor of the amount of money that I’m starting out with, rather than the amount of money that I receive after making the exchange.
I can think of two ways to tweak this.
- Make sure the two methods are clearly talking about what you have/receive after the exchange.
- Go more generic, and not talk about which side of the exchange it’s on (since technically it works for any currency). So instead of
budget
, maybeamount
orfunds
ortotal_value
.
Here’s an example of what “more generic” could look like:
def get_value_of_bills(denomination, number_of_bills):
"""
:param denomination: int - the value of a bill.
:param number_of_bills: int - number of bills of that denomination.
:return: int - total value of the bills.
"""
pass
def get_number_of_bills(amount, denomination):
"""
:param amount: float - the total amount of money available.
:param denomination: int - the value of a single bill.
:return: int - number of bills that can be obtained with the available funds.
"""
pass
The second thing that I was confused about was the exchangeable_value()
. I assumed that exchangeable
meant the amount that could be exchanged. In other words, I thought this was about the original currency rather than the target currency. After reading through the task description a few times I did figure it out, but I wonder if there’s a name that would help make it clearer that it’s about the target currency after the exchange. I can’t think of anything great off the top of my head, but maybe something like obtainable_value
?
I’d love to hear your thoughts.
If, after discussing this the community does come up with better names, I’d be happy to submit a pull request adjusting the exercise.