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
Without Function
# Input: number to check
num = int(input("Enter a number: "))
# Prime numbers are greater than 1
if num > 1:
# Check for factors
is_prime = True
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
is_prime = False
break
# Output the result
if is_prime:
print(f"{num} is a prime number")
else:
print(f"{num} is not a prime number")
else:
print(f"{num} is not a prime number")