diff options
| author | drbaggy <js5@sanger.ac.uk> | 2022-01-09 06:04:01 +0000 |
|---|---|---|
| committer | drbaggy <js5@sanger.ac.uk> | 2022-01-09 06:04:01 +0000 |
| commit | 29b9eeeb95555dbcf1f375c89910c83ac83abd8d (patch) | |
| tree | 857c2d4c063b88bedcebd76079cf488df977b330 /challenge-146/mohammad-anwar/python | |
| parent | d933e4e040eae5d2d4d69b6b4da2d312cd4887e4 (diff) | |
| parent | f2e062cd585f30ecbcf0257e72ccb8f0c82136a7 (diff) | |
| download | perlweeklychallenge-club-29b9eeeb95555dbcf1f375c89910c83ac83abd8d.tar.gz perlweeklychallenge-club-29b9eeeb95555dbcf1f375c89910c83ac83abd8d.tar.bz2 perlweeklychallenge-club-29b9eeeb95555dbcf1f375c89910c83ac83abd8d.zip | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-146/mohammad-anwar/python')
| -rw-r--r-- | challenge-146/mohammad-anwar/python/ch-1.py | 50 |
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() |
