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

Do you want to write an Algorithm to check for prime numbers. This code below is just what you need.

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: 👇 

COMMENTS

Name

Africa,13,Android,10,app,17,App of the week,12,Apple,1,Arts,1,Bitcademy,2,Blockchain,2,Crypto,1,Data Security,11,Developer,2,Facebook,4,Fintech,1,Games,1,Gmail,1,Google,10,How Tos,16,instagram,1,iOS,3,Mac,1,News,57,Photo,2,programming,4,Reviews,33,Rwanda,1,tech,7,Twitter,2,WhatsApp,1,YouTube,1,
ltr
item
ROTechnica: Python code and Algorithm to check if a number is prime number
Python code and Algorithm to check if a number is prime number
Do you want to write an Algorithm to check for prime numbers. This code below is just what you need.
https://images.pexels.com/photos/546819/pexels-photo-546819.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260
ROTechnica
https://www.rotechnica.com/2018/07/python-code-and-algorithm-to-check-if.html
https://www.rotechnica.com/
https://www.rotechnica.com/
https://www.rotechnica.com/2018/07/python-code-and-algorithm-to-check-if.html
true
4516553652693735627
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy