I am trying to modify my program to create two empty lists: prime and non_prime. and test if the random number in the list is a prime number or not a prime number. If the number is prime, I want to append it to prime number list. If not, I want to be able to add it to non_prime list. I tried to find the prime and non prime number from the random number list but I get the same output for prime and non prime number. Can anyone help me?
import random
def main():
num = [random.randint(1,100) for _ in range (20)]
print(num)
lowest = min(num)
print("The lowest number is: ", lowest)
highest = max(num)
print("The highest number is: ", highest)
total = 0.0
for value in num:
total += value
average = total / len(num)
print("The average is: " , average)
prime = [num]
for a in range (1, 101):
for b in range(2, a):
if a % b == 0:
break
else:
prime.append(a)
print("The prime numbers are: " , prime)
nonprime = [num]
for x in range (1, 101):
for y in range(2, x):
if x % y == 0:
break
else:
nonprime.append(x)
print("The non prime numbers are: " , nonprime)