Home > Problem, Projects/Experiments, Python > Python Project

Python Project



Python: Prime Numbera


Is it Prime

In a simple way, a Prime number is a number that cannot be made by multiplying other numbers. So 4 is Not Prime because we can say that 4 = 2 x 2, 6 is Not Prime because it can be produced by multiplying 3 x 2; but 5 Is Prime because we can’t find any integer numbers that can produce 5.

Numbers such as 1, 3, 5, 7, 11, 13 … all are Prime Numbers.


This function will ask the user to write a number then we will examine it to see whether it is a prime or not.



The Code:


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

result=”Prime”

for t in range (2,num):

if num%t==0 :

result=”Not Prime”

break

return result
print num,’is’,is_prime(num)








Follow me on Twitter..

Advertisements
  1. No comments yet.
  1. April 16, 2019 at 5:50 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s