From b900311560a2aaccd86c911d362838090ca1e2d9 Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Thu, 6 Jan 2022 20:04:01 +0000 Subject: - Added Python/Java solutions to the task "10001st Prime Number" of week 146. --- challenge-146/mohammad-anwar/python/ch-1.py | 50 +++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 challenge-146/mohammad-anwar/python/ch-1.py (limited to 'challenge-146/mohammad-anwar/python') diff --git a/challenge-146/mohammad-anwar/python/ch-1.py b/challenge-146/mohammad-anwar/python/ch-1.py new file mode 100644 index 0000000000..f41fdf9605 --- /dev/null +++ b/challenge-146/mohammad-anwar/python/ch-1.py @@ -0,0 +1,50 @@ +#!/usr/bin/python3 + +''' + +Week 146: + + https://theweeklychallenge.org/blog/perl-weekly-challenge-146 + +Task #1: 10001st Prime Number + + Write a script to generate the 10001st prime number. + +''' + +import math +import unittest + +def is_prime(n): + i = 2 + while (i <= int(math.sqrt(n))): + if ((n % i) == 0): + return 0 + i += 1 + + return 1 + +def find_prime(count): + c = 0 + n = 2 + while (c <= count): + if (is_prime(n) == 1): + c += 1 + if (c == count): + return n + n += 1 + +# +# +# Unit test class + +class TestFindPrimeNumber(unittest.TestCase): + + def test_example(self): + self.assertEqual( + find_prime(10001), + 104743, + 'Example' + ) + +unittest.main() -- cgit