aboutsummaryrefslogtreecommitdiff
path: root/challenge-144/cristian-heredia/python/ch-1.py
blob: 351dd6d381435c51dbbfe61589e6c12268fa2f8d (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
"""

    TASK #1 › Semiprime
    Submitted by: Mohammad S Anwar
    Write a script to generate all Semiprime number <= 100.

    For more information about Semiprime, please checkout the wikipedia page.


    In mathematics, a semiprime is a natural number that is the product of exactly two prime numbers. The two primes in the product may equal each other, so the semiprimes include the squares of prime numbers.


        Example
        10 is Semiprime as 10 = 2 x 5
        15 is Semiprime as 15 = 3 x 5

"""

primes = []
result = []
# Function to obtain all the primes numbers <= 100


def prime_numbers():
    for i in range(2, 101):
        primes.append(i)
        for j in range(2, i):
            if i % j == 0:
                primes.remove(i)
                break
    return primes


# Function to obtain all the semiprimes numbers <= 100
def semi_prime():
    for num in range(2, 101):
        for m in range(len(primes)):
            for n in range(len(primes)):
                if num == (primes[m] * primes[n]) and num not in result:
                    result.append(num)
    return result


prime_numbers()


# Print all the semiprimes numbers in a line, separated by ', '
print(*semi_prime(), sep=", ")