Prime checker in python with source code

Prime checker in python with source code

Introduction

Prime checker is a python based programming project. This program checks whether the number primer or not prime.

Prime number is actually a number divisible by only itself. Prime checker is a python version 3.9 based program. It is a program for checking prime or not prime. It is a simple program with few lines of code. The program asks the user to enter a random number and checks whether it is prime or not prime.

The program uses functions, for loop, boolean, and if else control statement. A function needs to be called to use this program. Range function is also used in this program that finds range between the numbers. See the code and output below.

n = int(input("Check this number: "))

def prime_checker(number = n):
    is_prime = True
    for i in range(2, n):
        if n % i == 0:
            is_prime = False
    if is_prime:
        print("It is a prime number")
    else:
        print("It is not a prime number")

prime_checker()

Output

prime checker

How to use this prime checker project?

  • Copy the code and paste it in your editor. (anaconda, pycharm)
  • Execute the program.
  • Check the prime number.
  • Enjoy and share