aboutsummaryrefslogtreecommitdiff
path: root/challenge-146/mohammad-anwar/python/ch-1.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-146/mohammad-anwar/python/ch-1.py')
-rw-r--r--challenge-146/mohammad-anwar/python/ch-1.py50
1 files changed, 50 insertions, 0 deletions
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()