Categories
By Aman Kharwal

Prime and Composite numbers with python

The most simplest python program to get Prime and Composite numbers.

Python program to get prime and composite numbers.

startNumber = 1
endNumber = 20
prime = []
composite = []
for i in range(startNumber,endNumber):
        for p in range(2, i):
            if (i % p)==0:
                composite.append(i)
                break
        else:
            prime.append(i)
print("prime: ",prime)
print("composite: ",composite)

#Output
prime: [1, 2, 3, 5, 7, 11, 13, 17, 19]
composite: [4, 6, 8, 9, 10, 12, 14, 15, 16, 18]

Leave a Reply