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:
print("prime: ",prime)
print("composite: ",composite)

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

Default image
Aman Kharwal

I am a programmer from India, and I am here to guide you with Data Science, Machine Learning, Python, and C++ for free. I hope you will learn a lot in your journey towards Coding, Machine Learning and Artificial Intelligence with me.

Leave a Reply

Do NOT follow this link or you will be banned from the site!