Write a program in Python to check if a number is prime.

By ayush goel in 22 Sep 2023 | 04:13 pm
ayush goel

ayush goel

Student
Posts: 346
Member since: 21 Sep 2023

Write a program in Python to check if a number is prime.

22 Sep 2023 | 04:13 pm
0 Likes
divas goyal

divas goyal

Student
Posts: 453
Member since: 22 Sep 2023

def is_prime(num):

    if num <= 1:

        return False

    for i in range(2, int(num**0.5) + 1):

        if num % i == 0:

            return False

    return True


num = 17  # Replace with your number

if is_prime(num):

    print(f"{num} is prime.")

else:

    print(f"{num} is not prime.")


22 Sep 2023 | 06:20 pm
0 Likes

Report

Please describe about the report short and clearly.