Skip to main content

Python program to check prime number or not

 Given an integer,Write a python program to check if an integer is a prime number or not.

Prime Number

A given a number is said to be prime if the number has exactly two factor which is 1 and itself or the number is said to be prime  if the number is divided by 1 and itself.

example -2 = factor of 2 is 1 and 2 so it is a prime because it has exactly two factor

Example:

1. 2 -prime

2. 1 - Not a prime

3. 3 -Prime

Python Program

def prime(n):
    #To count the factor of a number
    count = 0
    #we check from 2 because 1 is not a prime number
    if n > 1:
        for i in range(1,n+1):
            if n%i==0:
                count+=1
    else:
        return "Not a prime"
    #If the number has exactly 2 factor then we return as a prime number
    if count==2:
        return "Prime"
    else:
        return "Not a prime"
#Taking user input
n = int(input())
#calling the prime number function
print(prime(n))

Input:

2

Output:

Prime

Input:

1

Output:

Not a prime

Comments

Popular posts from this blog

Python automation with selenium.

Automate with selenium In this blog we are going to see how to automate some task with selenium. Selenium is an opensource framework which is used for testing web application by scrapping into the web site. To apply selenium in python for testing an application we need to follow some step. So in these this blog we are going to explain how to use selenium to go to the google and search for shotwithcode blog and read the blog. Step1: using pip in python we have to install selenium "pip install selenium" Step2: We need a web driver in which it will run the browser and tell the browser what to do. So if we use chrome we need to download chrome driver else if we use other browser then we need to download the web driver for that browser You can download the Chrome web driver here https://chromedriver.chromium.org/downloads Remember to download the chrome driver related to the chrome version we have Step3:After download the driver extract the file and save into a location which is e...

Why two factor authentication is very important?

Why two factor authentication is very important? Here is why two factor authentication is so much important to all of us, first i will start off with the meaning of two authentication What is a two factor authentication? Two factor authentication referred to us a two step of verification, Most of the user use one factor authentication to login to their social media or to any platform in the internet which has an authentication. So using a two factor authentication is where after giving the user name and password we also have to give a token or an OTP or any other details to verify that it was us who login into the platform. Example:   Suppose you sign-in into google with email if you use two factor authentication after you give the email and password while submitting the information google will send an OTP to your mobile phone number so that you can enter the OTP into the system, so if the OTP match then only the google will accept you login into google. So i hope by now you have a...

Best office computer accesories

 Here are some of the best computer accesories for your office at an affordable price in India. 1. Oxyura Gaming Mouse Pad Click here to see the Mouse pad https://amzn.to/3pVY8KL 2. Zebronics Zeb-Alex Wired Usb optical mouse Click here to see and buy the Mouse https://amzn.to/3ILT2t6 3. Usb wired keyboard Click here to see and buy the keyboard https://amzn.to/3mmzjqv 4.Laptop stand Click here to see and buy the laptop stand https://amzn.to/3dTgkih All link are from amazon so go ahead and check it out it is at an afordable price.