Project Euler

Check if Prime

      
      def check_prime(n):
        """test if x is prime using a Sieve of Eratosthenes"""
        #to account for negative primes
        n = abs(n)

        if type(n) != int:
          return False
        elif n == 1:
          return False
        elif n < 4:   #2 & 3 are prime
          return True
        elif n % 2 == 0:
          return False
        elif n % 3 == 0:
          return False

        else:
          j = 5
          while j <= int(n**0.5):
            if n % j == 0:
              return False
            j = j + 1
          return True