From 5563eebe527c335059516c9b14fb8063b727f565 Mon Sep 17 00:00:00 2001 From: Haidong Ji Date: Sun, 2 Sep 2018 16:32:00 -0500 Subject: Changing money algo done. --- .../sources/changingmoney.py | 17 ++++++++++++++++ .../tests/changingmoneyTest.py | 23 ++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 AlgoDesignAndTechniqueEdxPython/sources/changingmoney.py create mode 100644 AlgoDesignAndTechniqueEdxPython/tests/changingmoneyTest.py diff --git a/AlgoDesignAndTechniqueEdxPython/sources/changingmoney.py b/AlgoDesignAndTechniqueEdxPython/sources/changingmoney.py new file mode 100644 index 0000000..5369b9e --- /dev/null +++ b/AlgoDesignAndTechniqueEdxPython/sources/changingmoney.py @@ -0,0 +1,17 @@ +# Uses python3 +def getNumOfCoins(m): + # coins with denominations of 1, 5, and 10 + coinCount = 0 + remainder = 0 + if m / 10 == 0 & m % 10 == 0: + return m / 10 + coinCount = coinCount + int(m / 10) + remainder = m % 10 + if remainder >= 5: + return coinCount + 1 + remainder - 5 + else: + return coinCount + remainder + + +m = int(input()) +print(getNumOfCoins(m)) \ No newline at end of file diff --git a/AlgoDesignAndTechniqueEdxPython/tests/changingmoneyTest.py b/AlgoDesignAndTechniqueEdxPython/tests/changingmoneyTest.py new file mode 100644 index 0000000..efc681e --- /dev/null +++ b/AlgoDesignAndTechniqueEdxPython/tests/changingmoneyTest.py @@ -0,0 +1,23 @@ +''' +Created on Sep 2, 2018 + +@author: haidong +''' +import unittest + +from sources.changingmoney import getNumOfCoins + +class Test(unittest.TestCase): + + + def testName(self): + self.assertEqual(1, getNumOfCoins(1)) + self.assertEqual(2, getNumOfCoins(2)) + self.assertEqual(2, getNumOfCoins(6)) + self.assertEqual(6, getNumOfCoins(28)) + self.assertEqual(100, getNumOfCoins(1000)) + + +if __name__ == "__main__": + #import sys;sys.argv = ['', 'Test.testName'] + unittest.main() \ No newline at end of file -- cgit v1.2.3