Sum of Even numbers
Write a program to find the sum of even numbers in first N natural numbers.
The input is an integer N.
The output should be an integer containing the sum of even numbers upto the given number.
In the given example
N = 5, the even natural numbers below 5 are 2, 4 Then total = 2 + 4
So, the output should be
6.
value_of_N = int(input("Enter the value of N indicating highest natural number to include: "))
print(f"The sum of even numbers in the selected range is {sum([n for n in range(value_of_N+1) if n%2==0])}")
Comments
Leave a comment