Finding prime numbers in Python
问题 I need to write a function, is_prime() , which takes in an integer n > 1 and returns TRUE if the number is a prime number and False otherwise. But when I input 2, it always returns False . Is there anyway to correct this? def is_prime(x): if(x > 1): for i in range(2,x+1): if( x % i == 0): return False else: return True else: return False 回答1: Two issues: First issue is that range includes the number itself, which means that it will always return true (for numbers > 1) because prime numbers