>>> while True:
if num>1000:
break
if num%2==0:
sum=sum+num
num=num+1
>>> print(sum)
250500
>>> num=0
>>> sum=0
>>> while num<=1000:
num=num+1
if num %2==1:
continue
sum=sun+num
Traceback (most recent call last):
File "<pyshell#17>", line 5, in <module>
sum=sun+num
NameError: name 'sun' is not defined
>>> while num<=1000:
num=num+1
if num %2==1:
continue
sum=sum+num
>>> print(sum)
250498
都是1000以内偶数的和,为什么结果不一样
代码是没错误的,看看是不是格式错了