如果我尝试在其上运行isPrime
函数 - 用任何整数替换n
,它会发现它是否是素数;但是从a
获取b
和primes
作为数字范围以检查它们是否为素数是问题所在。
def primes(a,b):
pass
def isPrime(n):
# I want to make n take the values of a and b so that the is Prime
# function executes all the prime numbers within the range a to b
if n == 1:
return False
# here I've tried referencing n and (a,b) as the range but neither
# option does anything
for z in range(a, b):
if n % z == 0:
return False
else:
# this is supposed to print the n each time it comes up as a prime
# number but when I run this nothing happens and I'm not sure where
# I'm going wrong
print(n)
return True
答案 0 :(得分:0)
见下文:
def isPrime(n):
a = 2
b = 100000
if n == 1:
print("1 is not a prime number.")
return False
for z in range(a,b):
if n%z==0 and n != z:
print(str(n) + " is not a prime number.")
return False
print(str(n) + " is a prime number.")
return True