1 #! / Usr / bin / env python
2 #-*-coding: utf-8-*-
3 # Find the sum of all numbers 1-2 + 3-4 + 5 ... 99
4 "" "
5 Set start to 1 and sum to 0. The while loop is true when the start is less than 100.
6 The assignment of temp is equal to the remainder of start and 2. If the assignment of temp is equal to 1, the assignment of sum is equal to
7 sum plus start assignment (remainder is 1, start is odd), otherwise sum assignment is equal to sum minus start
8 assignment (the remainder is 0 if the remainder is not 1, and start is even), start is reassigned
9 is equal to start plus 1, until the assignment of start is equal to 99, the while loop is false! Print sum
10 "" "
11 start = 1
12 sum = 0
13 while start <100:
14 temp = start% 2
15 if temp == 1:
16 sum = sum + start
17 else:
18 sum = sum-start
19 #print (start)
20 #sum = sum + 1
21 start + = 1
22 print (sum)
Getting started with Python: finding all the numbers of 1-2+3-4+5...99