Using whileloops Write a program that reads an integer value

Using while-loop(s); Write a program that reads an integer value from the user and then prints prime if the number is a prime number, otherwise the program prints not prime. A prime number is a number that can only be divided by 1 and itself.

Solution

num=input(\"\") # this statement is to take the input from the user

# all prime numbers are greater than 1 so we check for that condition
if num > 1:
# check for factors because prime number can be divisible by either 1 or number itself
for i in range(2,num):
if (num % i) == 0:
print(num,\"is not a prime number\")

break
else:
print(num,\"is a prime number\")

Please while compiling don`t change the indentation as python strictly follows it

If you want the program in any other language please comment here so that I can give you the required answer in your required language

 Using while-loop(s); Write a program that reads an integer value from the user and then prints prime if the number is a prime number, otherwise the program pri

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site