From 3552056ccf6ea816f02874c2c10fa75b53da223a Mon Sep 17 00:00:00 2001 From: NAYON MAZUMDER <37953461+Nayonmazumder@users.noreply.github.com> Date: Sun, 9 Feb 2025 11:41:58 +0600 Subject: [PATCH] Update 02_solution.py This should be a correct solution for the problem as it asked to calculate the sum not count the even number on range ! --- 03_loops/02_solution.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/03_loops/02_solution.py b/03_loops/02_solution.py index ab37e93..672fc64 100644 --- a/03_loops/02_solution.py +++ b/03_loops/02_solution.py @@ -1,8 +1,19 @@ -n = 10 -sum_even = 0 +# n = 10 +# sum_even = 0 -for i in range(1, n+1): - if i%2 == 0: - sum_even += 1 +# for i in range(1, n+1): +# if i%2 == 0: +# sum_even += 1 -print("Sum of even number is: , ", sum_even) \ No newline at end of file +# print("Sum of even number is: , ", sum_even) + +# The Correct Solution would be : + +num = int(input("Please Enter a number : ")) +sum = 0 + +for nums in range(num+1): + if nums % 2 == 0: + sum += nums + +print(sum)