import math def isprime(num): """ Returns True if the input is a prime number, False otherwise """ for i in range(2, num): if num % i == 0: return False # a slightly faster version would be: # for i in range(2, int(math.sqrt(num)+1)): return True def first_primes(num): """ Prints out the first num primes """ count = 0 # the number of primes we've printed out current = 2 # the current number we're checking while count < num: if isprime(current): print current count += 1 current += 1 first_primes(10)