From 47b189c896e6478d5e74dc74d6e91fa6cbaffab9 Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Wed, 13 Jul 2022 23:55:31 +0100 Subject: - Added solutions to the task "Esthetic Number" of week 173. --- challenge-173/mohammad-anwar/python/ch-1.py | 38 +++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 challenge-173/mohammad-anwar/python/ch-1.py (limited to 'challenge-173/mohammad-anwar/python') 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() -- cgit