diff options
-rw-r--r-- | AlgoDesignAndTechniqueEdxPython/sources/changingmoney.py | 17 | ||||
-rw-r--r-- | AlgoDesignAndTechniqueEdxPython/tests/changingmoneyTest.py | 23 |
2 files changed, 40 insertions, 0 deletions
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 |