Answer to Question #237165 in Python for umesh

Question #237165

Sum of Even numbers

Write a program to find the sum of even numbers in first N natural numbers.

Input

The input is an integer N.

Output

The output should be an integer containing the sum of even numbers upto the given number.

Explanation

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.


1
Expert's answer
2021-09-15T23:40:21-0400
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])}")

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS