Python入门:求1-2+3-4+5...99的所有数的和
1 num =1
2 sum =0
3 while num <=99:
4 if num % 2 ==1:
5 sum = sum + num
6 num =num +1
7 print(sum)
2.求1-2+3-4+5...99的所有数的和
1 num =1
2 sum =0
3 while num <=99:
4 if num % 2 ==1:
5 sum = sum + num
6 else:
7 sum =sum -num
8 num =num +1
9 print(sum)