```
''' isprime2.py
a function to check if a positive integer is prime
prime numbers are only divisible by unity and themselves
integers less than 2 and even numbers other than 2 are not prime
tested with Python27 and Python33 by vegaseat 30aug2013
'''
def isprime2(n):
'''
check if integer n is a prime, return True or False
'''
# 2 is the only even prime
if n == 2:
return True
# integers less than 2 and even numbers other than 2 are not prime
elif n < 2 or not n & 1:
return False
# loop looks at odd numbers 3, 5, 7, ... to sqrt(n)
for i in range(3, int(n**0.5)+1, 2):
if n % i == 0:
return False
return True
# test ...
prime_list2 = []
for n in range(-50, 50):
if isprime2(n):
prime_list2.append(n)
print(prime_list2)
""" result ...
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
"""
```

**Are you able to help answer this sponsored question?**

Questions asked by members who have earned a lot of community kudos are featured in order to give back and encourage quality replies.

Recommended Topics