ROTechnica

Python code and Algorithm to check if a number is prime number

python_computer

Do you want to write an Algorithm to check for prime numbers. This code below is just what you need. Now let’s get started.

Algorithm to check for prime numbers

Step 1: Start

Step 2: Declare variables num, i

Step 3: Initialize variables
i= 2

Step 4: Read num from user.

Step 5: Repeat the steps until i<(num/2)
5.1 If remainder of n/i equals 0
Go to step 6

else Goto step 7

Step 6: display num is not a prime number

Step 7: display num is prime number

Step 8: stop

#Below is the python program… ???? 

PYTHON CODE

print(“To check for prime numbers “)

num= int(input(“Enter a number: “))

if num > 1:

 for i in range(2, num):

  if num%i == 0:

   print(num, ” is not a prime number”)

   print(i, ” times “, num//i, ” is “, num) 

   break

  else:

   print(num, ” is prime number”)

else:

print(num, ” is not prime “)

HOW TO DOWNLOAD AND RUN PYTHON PROGRAMS ON YOUR DEVICES

To run python on your android phone, download Qpython from playstore. You can click the link below :???? 


Also, 

Download the latest python IDE for your computer via the link below: ???? 

Related posts

How To Buy A Refurbished iPhone

Davide

Apple receives an EU Antitrust Charge over Mobile Payments

Tomiloba

Fisker Bets its Self-driving Automobile Machines will Ferry Future Commuters

ROTechnica

Leave a Comment

18 + one =

* By using this form you agree with the storage and handling of your data by this website.