aboutsummaryrefslogtreecommitdiff
path: root/challenge-146/mohammad-anwar/python/ch-1.py
blob: f41fdf96055b53ff8e421d04044119bb1f1cf4e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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()