This notebook was prepared by Donne Martin. Source and license info is on GitHub.
Refer to the Solution Notebook. If you are stuck and need a hint, the solution notebook's algorithm discussion might be a good place to start.
class CoinChanger(object):
def make_change(self, coins, total):
# TODO: Implement me
pass
The following unit test is expected to fail until you solve the challenge.
# %load test_coin_change_min.py
import unittest
class TestCoinChange(unittest.TestCase):
def test_coin_change(self):
coin_changer = CoinChanger()
self.assertRaises(TypeError, coin_changer.make_change, None, None)
self.assertEqual(coin_changer.make_change([], 0), 0)
self.assertEqual(coin_changer.make_change([1, 2, 3], 5), 2)
self.assertEqual(coin_changer.make_change([3, 2, 1], 5), 2)
self.assertEqual(coin_changer.make_change([3, 2, 1], 8), 3)
print('Success: test_coin_change')
def main():
test = TestCoinChange()
test.test_coin_change()
if __name__ == '__main__':
main()
Review the Solution Notebook for a discussion on algorithms and code solutions.