49. Python Program to find the Sum of n Even numbers.
How does this program work?
- In this program we are going to learn about how to find the Sum of n even numbers using Python.
- The integer entered by the user is stored in variable n.
- Declare variable 's' to store the sum of numbers and initialize it with 0.
- By using while loop we can add the sum of n even numbers.
Here is the code
n = ( int (input("Enter the maximum natural value till you want the sum of even numbers: ")))
i = 0
s = 0
while i <= n:
s+= i #(s = s+i)
i += 2
print("Sum of even natural numbers is: ",s)