About 58,700 results
Open links in new tab
  1. python - Fastest way of testing if a number is prime? - Stack …

    Oct 20, 2017 · Function isPrime1 is very fast to return False is a number is not a prime. For example with a big number. But it is slow in testing True for big prime numbers. Function …

  2. primes - isPrime Function for Python Language - Stack Overflow

    Mar 8, 2013 · Consider the prime number 5003: print is_prime(5003) Prints: 5 11 17 23 29 35 41 47 53 59 65 True The line r = int(n**0.5) evaluates to 70 (the square root of 5003 is …

  3. Determining Prime numbers in python function - Stack Overflow

    Nov 20, 2021 · def isprime(n): '''check if integer n is a prime''' # make sure n is a positive integer n = abs(int(n)) # 0 and 1 are not primes if n < 2: return False # 2 is the only even prime number if …

  4. checking prime number in python - Stack Overflow

    Jun 12, 2019 · Your problem is that the else part of your for-loop is wrong. You print "the number is prime" every time a division check fails, not just at the end.

  5. how to find a prime number function in python - Stack Overflow

    using your code, and focusing on code structure: def is_prime(x): # function contents must be indented if x == 0: return False elif x == 1: return False # your base cases need to check X, not …

  6. Simple prime number generator in Python - Stack Overflow

    Mar 18, 2019 · import math import itertools def create_prime_iterator(rfrom, rto): """Create iterator of prime numbers in range [rfrom, rto]""" prefix = [2] if rfrom < 3 and rto > 1 else [] # include 2 if …

  7. python - Validate if input number is prime - Stack Overflow

    Feb 2, 2022 · >>> def isPrime(k): # 1 is not prime number if k==1: return False # 2, 3 are prime if k==2 or k==3: return True # even numbers are not prime if k%2==0: return False # check all …

  8. Python: determining if a number is prime - Stack Overflow

    Nov 24, 2014 · Also, that x = Prime is going to raise a NameError, because there's nothing named Prime. Given that it doesn't actually do anything at all, you should just delete it. Of course that …

  9. How to use a for loop to check if a number is prime? (python)

    Oct 16, 2021 · Enter a positive number to test: 15 2 is not a divisor of 15 ... continuing 3 is a factor of 15 ...stopping 15 is a not a prime number 15 is a prime number The problem is in your bool …

  10. efficiently finding prime numbers in python - Stack Overflow

    Sep 28, 2017 · here is my code: def findPrimes(): prime=True c=0 n=1 while n&lt;14: n=n+1 for i in range(1,n): if n%i==0: prime=False if prime==Tru...

Refresh