Write a Python program to Separate positive numbers from negative and print the positive numbers and negative numbers separately
Topic: Write a Python program to Separate positive numbers from negative and print the positive numbers and negative numbers separately
Solution
from random import random a = [] for i in range(7): n = int(random() * 20) - 10 a.append(n) print(a) neg = [] pos = [] for i in a: if i < 0: neg.append(i) elif i > 0: pos.append(i) print(neg) print(pos)
List all Python Programs