Welcome to Foundation of Data Science Laboratory
Welcome to Foundation of Data Science Laboratory
Write a Python program to find the a number is prime or not
With Function
def is_prime(num):
# Prime numbers are greater than 1
if num <= 1:
return False
# Check for factors
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
return False
return True
# Input: number to check
num = int(input("Enter a number: "))
# Output the result
if is_prime(num):
print(f"{num} is a prime number")
else:
print(f"{num} is not a prime number")