0% found this document useful (0 votes)
29 views1 page

Prime

The document discusses ways to check if a number is prime, including checking if it is only divisible by 1 and itself, using a function, and checking numbers within a range.

Uploaded by

Darshan N.N
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views1 page

Prime

The document discusses ways to check if a number is prime, including checking if it is only divisible by 1 and itself, using a function, and checking numbers within a range.

Uploaded by

Darshan N.N
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

# To solve this problem we have to know what is prime number

# Prime Number Means the number is divisible by 1 and itself

# Here we have to check the condition

#TODO case-1 : My number is always greater than 1

#TODO case-2 : if my number is divisible by any other number except 1 and itself
then my number is not a PRIME number

#TODO Normal way without using function

number = int(input("Enter the Number: "))

if number > 1:
for i in range(2,number):
if (number % i == 0):
print("%d is not a prime number"%(number))
break
else:
print("%d is Prime number"%(number))

#TODO Using function

def Prime(num):

if num > 1:
for i in range(2, num):
if (num % i == 0):
print("%d is not a Prime Number" %(num))
print("Becouse it is divisible by",num//i,i,num)
break
else:
print("%d is a Prime Number" %(num))

if __name__ == '__main__':
number = int(input("Enter the Number: "))
Prime(number)

#TODO Prime Numbers within a specific range()

def Prime(num,range1,range2):

for num in range(range1,range2):


if num > 1:
for i in range(2,num):
if (num % i == 0):
break
else:
print(num)

num = int(input("Enter the Number: "))


range1 = int(input("Enter the range 1: "))
range2 = int(input("Enter the range 2: "))
Prime(num,range1,range2)

You might also like