Python program to Get Positive Numbers Out of Negative Numbers

import random
x = []
for i in range(20):
 x.append(int(random.random()*20)-10)
print(x)
pos = []
neg = []
for i in x:
 if i<0:
  neg.append(i)
 elif i>0:
  pos.append(i)
print("Negative numbers = ",neg)
print("Positive numbers = ",pos)

 

 

Output:

[-10, 3, 8, -10, 2, -9, -10, 7, 9, -7, -3, 5, -7, 4, 3, -5, 2, 8, -5, -9]
Negative numbers =  [-10, -10, -9, -10, -7, -3, -7, -5, -5, -9]
Positive numbers =  [3, 8, 2, 7, 9, 5, 4, 3, 2, 8]

 

[8, 6, -9, -2, 0, 0, -2, -6, -2, -1, 2, -9, -7, -7, -5, -5, 4, -7, -4, -8]
Negative numbers =  [-9, -2, -2, -6, -2, -1, -9, -7, -7, -5, -5, -7, -4, -8]
Positive numbers =  [8, 6, 2, 4]

Subscribe For Daily Updates