aboutsummaryrefslogtreecommitdiff
path: root/challenge-144/sgreen/python/ch-1.py
diff options
context:
space:
mode:
authorLuis Mochan <mochan@fis.unam.mx>2021-12-23 09:31:38 -0600
committerLuis Mochan <mochan@fis.unam.mx>2021-12-23 09:31:38 -0600
commitc715c9c6a28663983f51848c96699ffb23e6189f (patch)
tree6e8d0ac1bc1438f1e0cd4a7ac609dda25dd66bf0 /challenge-144/sgreen/python/ch-1.py
parent0d456859d24f97ef36d88da5b067b49baa833aa0 (diff)
parentb369a8ed20a9d70d0d2500c5bd693b8be678f2c1 (diff)
downloadperlweeklychallenge-club-c715c9c6a28663983f51848c96699ffb23e6189f.tar.gz
perlweeklychallenge-club-c715c9c6a28663983f51848c96699ffb23e6189f.tar.bz2
perlweeklychallenge-club-c715c9c6a28663983f51848c96699ffb23e6189f.zip
Merge branch 'master' of github.com:manwar/perlweeklychallenge-club into challenges
Diffstat (limited to 'challenge-144/sgreen/python/ch-1.py')
-rwxr-xr-xchallenge-144/sgreen/python/ch-1.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/challenge-144/sgreen/python/ch-1.py b/challenge-144/sgreen/python/ch-1.py
new file mode 100755
index 0000000000..0301f27de9
--- /dev/null
+++ b/challenge-144/sgreen/python/ch-1.py
@@ -0,0 +1,36 @@
+#!/usr/bin/env python
+
+def get_primes():
+ primes = []
+ # Return a list of all primes between 2 and 50 (being 100 รท 2)
+ for i in range(2, 51):
+ for d in range(2, int(i / 2) + 1):
+ # If the number is divisable by something other than one and
+ # itself, it's not a prime
+ if i % d == 0:
+ break
+ else:
+ # It's a prime
+ primes.append(i)
+
+ return primes
+
+
+def main():
+ primes = get_primes()
+ semiprimes = []
+
+ for i in primes:
+ for j in primes:
+ x = i * j
+ if x > 100:
+ break
+ if x not in semiprimes:
+ semiprimes.append(x)
+
+ semiprimes.sort()
+ print(*semiprimes, sep=', ')
+
+
+if __name__ == '__main__':
+ main()