100以内1-2+3-4+...+99-100和为:
count=1 s = 0 while count<101: temp=count%2 if temp==0: s=s-count else: s=s+count count=count+1 print('100以内1-2+3-4+...+99-100和为:',s) print('-----end-----')
输出结果为:
100以内1-2+3-4+...+99-100和为: -50
-----end-----
count=1 s = 0 while count<101: temp=count%2 if temp==0: s=s-count else: s=s+count count=count+1 print('100以内1-2+3-4+...+99-100和为:',s) print('-----end-----')
输出结果为:
100以内1-2+3-4+...+99-100和为: -50
-----end-----