定义函数来做更简单明了,但还是要注意变量名的取法

while True:
    try:
        n = int(input())
        out = 0
        def n_sum(a):
            res = 0
            for i in range(1,a):
                if a%i ==0:
                    res+=i
            return res
        for i in range(1,n+1):
            if i==n_sum(i):
                out+=1
        print(out)
    except:break