DAY3(PYTHON)

一、or 和and的区别

X OR Y,如果X非0,则为X

X OR Y,如果X为真,则为Y

二、continue 跳出当次循环

  break 跳出循环

三、#输出1-2+3-4+5-6+。。。。。。-98+99(除了88以为的和)

-*-enconding:UTF-8-*-

i=1

sum=0

while i<100:

i++

if i%2!=0:

sum=sum+i

if i==88:

i++

continue

else:

sum=sum-i

print(sum)

如果后面改为+87+89-90+。。。-99;

可以改写代码:

i=0

j=-1

sum=0

while i<99:

i=i+1

if i==88:

continue

else:

j=-j

sum=sum+i*j

print(sum)

猜你喜欢

转载自www.cnblogs.com/qq946487854/p/9771651.html