Prime finder


#1

This is my problem:

Define a function called is_prime that takes a number x as input.

For each number n from 2 to x - 1, test if x is evenly divisible by n.

If it is, return False.

If none of them are, then return True.

THIS IS WHAT I WROTE:

def is_prime(x):
if x < 2:
return False
if x == 2:
return True
if x == 3:
return True
for i in range(2, x-1):
if x % i == 0:
return False
else:
return True

What am i doing wrong?

I tried scripts fomr foruns but they did not work


#2

Is that code inside the loop?

Don’t need the above.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.