用for循环计算(1-3+5-7...99)的结果(两种方法)
1) sum=0 count=1 for i in range(1,100,2): if count % 2==0: sum = sum - i else: sum = sum + i count = count+1 print(sum)
2) sum = 0 count = 1 for i in range(1,100,2): sum = sum + i*count count = -count print(sum)
1) sum=0 count=1 for i in range(1,100,2): if count % 2==0: sum = sum - i else: sum = sum + i count = count+1 print(sum)
2) sum = 0 count = 1 for i in range(1,100,2): sum = sum + i*count count = -count print(sum)