question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Currency Exchange] Inconsistent change value type (`float`/`int`)

See original GitHub issue

Exchanged value is of type float:

https://github.com/exercism/python/blob/48e47c1f6af8050e135747461085d713a3231164/exercises/concept/currency-exchange/exchange.py#L6

Remaining value is of type float as well:

https://github.com/exercism/python/blob/48e47c1f6af8050e135747461085d713a3231164/exercises/concept/currency-exchange/exchange.py#L17

Value exchangeable in bills of a certain denomination is of type int, but that is justifiable because denominations are integers:

https://github.com/exercism/python/blob/48e47c1f6af8050e135747461085d713a3231164/exercises/concept/currency-exchange/exchange.py#L52

However, non-exchangeable value is of type int as well, which I believe is inconsistent:

https://github.com/exercism/python/blob/48e47c1f6af8050e135747461085d713a3231164/exercises/concept/currency-exchange/exchange.py#L65

Given the established structure, I see no reason why the non-exchangeable value should be integer. I mean, it clearly is not integer, but has to be rounded artificially to pass the tests.


Overall, I was surprised how convoluted this seemingly simple exercise was.

For one, there are few opportunities to reuse code in exchangeable_value (task 5) and non_exchangeable_value (task 6). The essence of both of these functions is to calculate the exchangeable amount given the spread, which could’ve been implemented in exchange_money (task 1). Then exchangeable_value could potentially reuse get_value_of_bills (task 3), whereas non_exchangeable_value could potentially reuse get_change (task 2) – except for the fact that it expects an integer, therefore this issue.

As a side note, if we’re really looking to encourage the usage of the modulo operator %, we could introduce a task to convert amounts using different denominations (and e.g. calculate the remainder that cannot be converted).

Happy to discuss & potentially submit a PR.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
pranasziaukascommented, Aug 25, 2022

Hello and thanks for your thoughtful (as always) response @BethanyG.

Just let me know how you’d like to proceed - I am open to revamp, replacement, and/or extension.

Since I’m still an infrequent visitor, not really comfortable to do a deep strategic dive. I will iterate the current exercise to hopefully make things more consistent and friendly to further changes.

PR incoming!

1reaction
pranasziaukascommented, Aug 22, 2022

Sorry, I still intend to circle back to this @BethanyG. I opened this issue just before my vacation thinking I might have some spare time while traveling, but I was wrong 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Inconsistent results while printing float as integer [duplicate]
you're not casting the float, printf is just interpreting it as an integer which is why you're getting seemingly garbage values. Edit:.
Read more >
Cleaning Up Currency Data with Pandas
This article summarizes my experience and describes how to clean up messy currency fields and convert them into a numeric value for further ......
Read more >
Error bands must have compatible data types; found ...
I have tried to export this image to my drive and I get the next error: bands must have compatible data types; found...
Read more >
Inconsistent float to string vs. string to float casting - externals.io
Hi! Regarding the decimal separator (aka. decimal point), the behavior of casting float to string is inconsistent with casting string to float.
Read more >
Exchange Rates in 2023: A Guide for Anyone Sending ...
Compared to floating exchange rates, this type of rate keeps a currency's value within a certain range and is generally used to maintain...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found