Program to check whether a given number is prime or not using a while loop in Python:

 # While loop in Python - Checking if a number is prime

num = int(input("Enter a number: "))

is_prime = True

i = 2

while i <= num//2:

    if num % i == 0:

        is_prime = False

        break

    i += 1

if is_prime:

    print(num, "is a prime number")

else:

    print(num, "is not a prime number")


Comments

Popular posts from this blog

Simple Python Program Code for Snake Game

Iris Flowers Classification ML Project with Code

Linear Regression Model for House Price Prediction in Python