Saturday, 4 January 2020

Python program to print Sum of even numbers between 1 to 100

Python program to print sum of even numbers between 1 to 100 (2 + 4 + 6 + .... + 100). 


Concept to learn: Python while loop


# Python program to print sum of even numbers between 1 to 100 (2+4+6...+100) using while loop.

sum = 0
num = 0

while(num <= 100):
    sum = sum + num
    num = num + 2
print("Sum of even numbers between 1 to 100 is ", sum)


Output of Program

Sum of even numbers between 1 to 100 is 2550

No comments:

Post a Comment