Answer to Question #325984 in Python for raster

Question #325984

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.


1
Expert's answer
2022-04-08T09:31:44-0400
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")

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS