Question: I came across this (really) simple program a while ago. It just outputs the first x primes. I'm embarrassed to ask, is there any way to make it more "pythonic" ie condense it while making it (more) readable? Switching functions is fine; I'm only interested in readability.

Thanks

```
from math import sqrt

def isprime(n):
  if n ==2:
    return True
  if n % 2 ==0 : # evens
    return False

  max = int(sqrt(n))+1 #only need to search up to sqrt n 
  i=3
  while i <= max: # range starts with 3 and for odd i
    if n % i == 0:
      return False
    i+=2

  return True

reqprimes = int(input('how many primes: '))
primessofar = 0
currentnumber = 2
while primessofar < reqprimes:

  result = isprime(currentnumber)

  if result:
     primessofar+=1
     print currentnumber
     #print '\n'

  currentnumber += 1

```

Answer: 
Firstly, you should not assign max to a variable as it is an inbuilt function used to find the maximum value from an iterable. Also, that entire section of code can instead be written as

```
for i in xrange(3, int(sqrt(n))+1, 2):
    if n%i==0: return False

```

Also, instead of defining a new variable result and putting the value returned by isprime into it, you can just directly do

```
if isprime(currentnumber):

```
You can make it more pythonic with sieve algorithm (all primes small than 100):

```
def primes(n):
    sieved = set()
    for i in range(2, n):
        if not(i in sieved):
            for j in range(i + i, n, i):
                sieved.add(j)
    return set(range(2, n)) - sieved

print primes(100)

```

A very small trick will turn it to your goal.