使用范围的ZeroDivisionError

jer*_*144 -8 python python-3.x

我一直在接受ZeroDivisionError.我的代码如下.什么似乎是我的问题?

def number(x):
    for i in range(x):
        if x%i == 0:
            print(i)
Run Code Online (Sandbox Code Playgroud)

Sim*_*ser 6

您可以从1开始迭代而不是0:

def number(x):
    for i in range(1, x):
        if x % i == 0:
            print(i)
Run Code Online (Sandbox Code Playgroud)