Write a python script that checks if integer numbers between 1 and an integer input from a user are prime numbers (Hint: use the range function to loop between 0 and an integer input).
In a case where prime numbers are identified then add all prime numbers to a new list and display the list, in case where a number is not a prime number display an error message.
def is_prime(num):
for i in range(2,num//2):
if num%i == 0:
return False
return True
n = int(input())
primes_list = []
for i in range(1,n+1):
if is_prime(i):
primes_list.append(i)
if primes_list:
print(primes_list)
else:
print("there is no prime numbers")
Comments
Leave a comment