Header Ads

Separate Prime and Composite Number into Two Different List using Python

 Program Source Code

myList = []
n =
int(input("Enter Lenth:"))
for a in range(1,n+1):
    e =
int(input("Enter Element:"))
    myList.append(e)
print("list is ")
print(myList)
l =
len(myList)
prime = []
nprime = []
for i in range(0 , l):
    c =
0
   
for j in range(2,myList[i]):
       
if myList[i]%j == 0:
            c=
1
           
break
    if
c == 0:
        prime.append(myList[i])
   
else:
        nprime.append(myList[i])

print(prime)
print(nprime)


Output



Related Video




No comments

Powered by Blogger.