为什么无法打印范围?定义是素数函数错了吗?

时间:2017-05-28 23:06:55

标签: python range

def isprime(a):
    sum = 0
    x = 1

    if(a % x == 0):
        sum += x
    x += 1

    if (a + 1 == sum):
        return True
    elif (a + 1 != sum):
        return False

    return True

for num in range (1, 101):
    if(isprime(a) == True):
        print(a)

1 个答案:

答案 0 :(得分:1)

你的循环变量是'num',而不是'a'

for num in range (1, 101):
    if isprime(num):
        print(num)