def is_prime(x):

```
if x < 2:
return False
elif x == 2:
return True
elif x == 9:
return False
for n in range(2, x):
if x % n == 0:
return False
else:
return True
```

Now it says 15 can't do it

def is_prime(x):

```
if x < 2:
return False
elif x == 2:
return True
elif x == 9:
return False
for n in range(2, x):
if x % n == 0:
return False
else:
return True
```

Now it says 15 can't do it

Is_prime

The instructions for this exercise are pretty clear, and if we follow them without being too creative, we end with a basic brute force prime number tester.

- Primes are integers that are greater than 1.
- 2 is the only even Prime.
- Primes have no divisors other than themselves and 1.

We will not want our program to be testing for every number. That is for our loop to take care of. There are really only two conditionals given in the instructions.

```
if x < 2: return False
for n in range(2, x):
if x % n == 0: return False
return True
```

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