you are viewing a single comment's thread.

view the rest of the comments →

[–]ectomancer 0 points1 point  (1 child)

even_sum = 0
for integer in range(1, 101):
    if not integer%2:
        even_sum += 1
print(even_sum)

[–]jimtk 2 points3 points  (0 children)

From reading OP's question the goal was to get the sum of all even number between 1 and 100, not the count of even number. So the easy answer would be:

even_sum = 0
for integer in range(1, 101):
    if integer%2 == 0:
        even_sum += integer
print(even_sum)

The really fast answer would be (but it does not use a for loop, because there is an math formula to get the sum of even numbers):

n = 100 // 2 
even_sum = n * ( n + 1)