Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a8a7009

Browse files
Merge pull request #197 from The-APK/main
Added Documentation and Formatting.py
2 parents f2d9636 + b0807cd commit a8a7009

File tree

1 file changed

+29
-20
lines changed
  • S/Split a list into nonprime & prime

1 file changed

+29
-20
lines changed
Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
1-
n=int(input("ENTER THE SIZE OF THE list1"))
2-
p=[]
3-
np=[]
4-
l=[]
5-
o=[]
6-
f=0
7-
print("Enter the no.s")
8-
for i in range(0,n):
9-
e= int(input())
10-
for j in range(1,n):
11-
if(e%j==0):
12-
f+=1
13-
if(f==1):
14-
p.append(e)
1+
# Get the size of the list1 from the user
2+
n = int(input("Enter the size of the list1: "))
3+
4+
# Initialize lists for prime and non-prime numbers
5+
prime_list = []
6+
non_prime_list = []
7+
8+
# Prompt the user to enter numbers
9+
print("Enter the numbers:")
10+
for i in range(n):
11+
e = int(input())
12+
f = 0 # Reset the factor count for each number
13+
14+
# Check if the number is prime or non-prime
15+
for j in range(2, e):
16+
if e % j == 0:
17+
f += 1
18+
break # No need to continue checking, it's not prime
19+
if f == 0:
20+
prime_list.append(e)
1521
else:
16-
np.append(e)
17-
f=0
18-
print("prime list")
19-
print(p)
20-
print("Non prime list")
21-
print(np)
22+
non_prime_list.append(e)
23+
24+
# Print the prime numbers
25+
print("Prime numbers list:")
26+
print(prime_list)
27+
28+
# Print the non-prime numbers
29+
print("Non-prime numbers list:")
30+
print(non_prime_list)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /