File tree 1 file changed +29
-20
lines changed
S/Split a list into nonprime & prime
1 file changed +29
-20
lines changed Original file line number Diff line number Diff line change 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 )
15
21
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 )
You can’t perform that action at this time.
0 commit comments