top of page
learn_data_science.jpg

Data Scientist Program

 

Free Online Data Science Training for Complete Beginners.
 


No prior coding knowledge required!

Python Program to Check Prime Number

Writer's picture: Marawan MohamedMarawan Mohamed


In this article an example to check whether an integer is a prime number or not using for loop and if...else statement. If the number is not prime, it's explained in output why it is not a prime number.



Understanding Prime Number


A positive integer greater than 1 has no other factors except 1 and the number itself is called a prime number. 2, 3, 5, 7, etc. are prime numbers as they do not have any other factors.



Creating the App


We will start by taking a number from the user.


In this program, we have checked if the num is prime or not. Numbers less than or equal to 1 are not prime numbers. Hence, we only proceed if the num is greater than 1 and check if the num is exactly divisible by any number from 2 to num - 1. If we find a factor in that range, the number is not prime, so we set a flag to True and break out of the loop.


Outside the loop, we check if the flag is True or False.

  • If it is True, the num is not a prime number.

  • If it is False, the num is a prime number.


Great!, We have successfully made a Python Program to Check Prime Numbers. Let's see the full file,


0 comments

Recent Posts

See All

Comments


COURSES, PROGRAMS & CERTIFICATIONS

 

Advanced Business Analytics Specialization

Applied Data Science with Python (University of Michigan)

Data Analyst Professional Certificate (IBM)

Data Science Professional Certificate (IBM)

Data Science Specialization (John Hopkins University)

Data Science with Python Certification Training 

Data Scientist Career Path

Data Scientist Nano Degree Program

Data Scientist Program

Deep Learning Specialization

Machine Learning Course (Andrew Ng @ Stanford)

Machine Learning, Data Science and Deep Learning

Machine Learning Specialization (University of Washington)

Master Python for Data Science

Mathematics for Machine Learning (Imperial College London)

Programming with Python

Python for Everybody Specialization (University of Michigan)

Python Machine Learning Certification Training

Reinforcement Learning Specialization (University of Alberta)

Join our mailing list

Data Insight participates in affiliate programs and may sometimes get a commission through purchases made through our links without any additional cost to our visitors.

bottom of page