def sum(d,a):
b = 0
c = 1
while b <=a:
b = b + c
c = c + 1
return b
print(sum(1,101))
因为你的代码里,因为c也一直在增加,b循环不到一百次就早已经大于100了
更正:
def my_sum(n1,n2):
result=0
num=n1
while num<=n2:
result+=num
num+=1
return result
print(my_sum(1,100))