From fd95c790e4b5d2590b0feaeb8f15eeb48104d7dc Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Sat, 4 Dec 2021 15:56:01 +0000 Subject: - Added Python solutions to week 141. --- challenge-141/mohammad-anwar/python/ch-1.py | 46 +++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 challenge-141/mohammad-anwar/python/ch-1.py (limited to 'challenge-141/mohammad-anwar/python/ch-1.py') diff --git a/challenge-141/mohammad-anwar/python/ch-1.py b/challenge-141/mohammad-anwar/python/ch-1.py new file mode 100644 index 0000000000..b07284649b --- /dev/null +++ b/challenge-141/mohammad-anwar/python/ch-1.py @@ -0,0 +1,46 @@ +#!/usr/bin/python3 + +''' + +Week 141: + + https://theweeklychallenge.org/blog/perl-weekly-challenge-141 + +Task #1: Number Divisors + + Write a script to find lowest 10 positive integers having exactly 8 divisors. + +''' + +import unittest + +def number_divisors(count, number): + numbers = [] + i = 1 + + while len(numbers) < count: + divisors = [] + for j in range(1, i+1): + if i % j == 0: + divisors.append(j) + + if len(divisors) == number: + numbers.append(i) + + i += 1 + + return numbers + +# +# +# Unit test class + +class TestJortSort(unittest.TestCase): + + def test_example_1(self): + self.assertEqual( + number_divisors(10, 8), + [24, 30, 40, 42, 54, 56, 66, 70, 78, 88], + 'Example 1') + +unittest.main() -- cgit