Python program to check number is prime or not

 

Python program to check whether the given number is prime or not

Write a Python program to accept a number from the user, and check whether the given number is a Prime Number or Not

Video Tutorial

What is the meaning of a Prime Number..?

A number is said to be prime if it is not divisible by any other number except by 1 and itself.

For Example:

2, 3, 5, 7, and so on are prime numbers

4, 6, 8, 10, 12, 15, and so on are not prime numbers

Source Code of Prime Number Program in Python

num = int (input("Enter the number: "))
flag = 0
for i in range(2, num):
    if (num % i == 0):
        flag = 1
        break
        
if (flag == 0):
    print("The number is prime")
else:
    print ("The number is not a prime")

Output:

Case 1:

Enter the number: 66

The number is not a prime

Case 2:

Enter the number: 67

The number is prime

Summary:

This tutorial discusses how to write a Python program to verify a number is prime or not. If you like the tutorial share it with your friends. Like the Facebook page for regular updates and YouTube channel for video tutorials.

Leave a Comment

Your email address will not be published. Required fields are marked *

Welcome to VTUPulse.com


Computer Graphics and Image Processing Mini Projects -> Click Here

Download Final Year Project -> Click Here

This will close in 12 seconds