Write a program to check if a number is prime or not. and also print all Prime Numbers in given Interval by user.
Q. Write a program to
(i) Check if a number is prime or not.
(ii) Print all Prime Numbers in given Interval by user.
Code:-
(i)
def primecheck(n):
if n > 1:
for i in range(2,int(n/2)+1):
if (n % i) == 0:
print(n,"is not a prime number.")
break
else:
print(n,"is a prime number.")
else:
print(n,"is not a prime number.")
n = int(input("Enter a number:"))
primecheck(n)
Output:-
Code:-
(ii)
Comments
Post a Comment