aboutsummaryrefslogtreecommitdiff
path: root/challenge-173/mohammad-anwar/python
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-173/mohammad-anwar/python')
-rw-r--r--challenge-173/mohammad-anwar/python/ch-1.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/challenge-173/mohammad-anwar/python/ch-1.py b/challenge-173/mohammad-anwar/python/ch-1.py
new file mode 100644
index 0000000000..5d9e80c567
--- /dev/null
+++ b/challenge-173/mohammad-anwar/python/ch-1.py
@@ -0,0 +1,38 @@
+#!/usr/bin/python3
+
+'''
+
+Week 173:
+
+ https://theweeklychallenge.org/blog/perl-weekly-challenge-173
+
+Task #1: Esthetic Number
+
+ You are given a positive integer, $n.
+
+ Write a script to find out if the given number is Esthetic Number.
+
+'''
+
+import unittest
+
+def is_esthetic_number(n):
+ s = str(n)
+ for i in range(1, len(s)):
+ if abs(int(s[i-1]) - int(s[i])) != 1:
+ return False
+ return True
+
+#
+#
+# Unit test class
+
+class TestPrimePartition(unittest.TestCase):
+
+ def test_example_1(self):
+ self.assertTrue(is_esthetic_number(5456))
+
+ def test_example_2(self):
+ self.assertFalse(is_esthetic_number(120))
+
+unittest.main()