Exercise: Calculate Coin Change
Bartosz Zaczyński RP Team on Oct. 30, 2026
@Ferchran good catch, Angelo. You’re right that 90 cents is a useful test case. If you write pennies = remainder after calculating the nickels, then the leftover nickel gets counted as 5 pennies.
Your fix works. The solution for this exercise does the same thing in one line by using % one more time:
nickels = remainder // 5
pennies = remainder % 5
With total_cents = 90, this prints:
3 quarters
1 dimes
1 nickels
0 pennies
The tests only check the starting value of 87 cents, where there are no nickels, so they don’t catch this mistake. Trying other amounts like you did is a good way to find bugs like this one. I’ll pass this along to the rest of the team so we can make the tests stricter.
Thanks for the kind words about the site 🙂
Become a Member to join the conversation.
Ferchran on Oct. 25, 2026
Hello guys! Just to confirm my thesis. If you run this exercise with 90 cents, will it give a wrong answer like:
The solution is to just add another line of reminder = reminder % 5 below nickels. PS. Found your website wonderful! Regards Angelo.