Table of Contents
Introduction
In this section of python programing, we will understand the python to check whether the given number is prime or not. A prime no is the positive integer which is divisible by 1 or number itself.
Program
num = int(input("Please enter the number to check: ")) if num > 1: for i in range(2, num): if (num%i) == 0: print("The number is not prime!") break else: print("The number is prime number") else: print("The number is not prime!")
Output
Explanation
In the above python code we have created a variable num which stores integer input from user. After that if condition checks whether the input is positive integer of or not and in case the condition satisfies the for loop iterates from 2 to num/2. If the num given is divided by any other number then the number is not prime otherwise the number is prime.
0 Comments