summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaidong Ji2018-09-02 16:32:00 -0500
committerHaidong Ji2018-09-02 16:32:00 -0500
commit5563eebe527c335059516c9b14fb8063b727f565 (patch)
tree78faa3968183119137cdb8aae670b35a28b9a532
parenta6fbcd67ecf83f4715a7fff4ae52cdf91687c8d6 (diff)
Changing money algo done.
-rw-r--r--AlgoDesignAndTechniqueEdxPython/sources/changingmoney.py17
-rw-r--r--AlgoDesignAndTechniqueEdxPython/tests/changingmoneyTest.py23
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