Write a method isprime that determines whether or not a numb

Write a method is_prime that determines whether or not a number is prime. Prime numbers can only be evenly divided by 1 and themselves. For simplicity you can assume that \'n >= 2\'.

Solution

## definition for is_prime
def is_prime(n):
if n>= 2:
for i in range(2,n): ## looping upto
if not ( n % i ): ## divided by 1 and themselves
print(\" Not Prime number\");
else:
print(\" Not Prime number\");
print(\"Prime number\");

  
##print(is_prime(3));

******************* output*************

>>> is_prime(7)
Prime number
>>> is_prime(3)
Prime number
>>> is_prime(2)
Prime number
>>>

 Write a method is_prime that determines whether or not a number is prime. Prime numbers can only be evenly divided by 1 and themselves. For simplicity you can

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site