 Python Program to Find Sum Of Even and Odd numbers From 1 to N

Python program to calculate the sum of even and odd numbers from 1 to N(10, 50 100, 1000); Through this tutorial, you will learn how to print the sum of even and odd numbers from 1 to N (10, 100, 500, 1000).

Python Program to Calculate Sum Of Even and Odd numbers From 1 to N

• Python Program to Find Sum Of Even numbers From 1 to N
• Python Program to Find Sum Of Odd numbers From 1 to N

Python Program to Find Sum Of Even numbers From 1 to N

Use the following steps to find or calculate sum of even number from 1 to n in python:

• Take the input number from 1 to that user-entered value
• Define a variable, which name total
• Iterate for loop and check each number using num%2 == 0 formula is it even or not.
• If the number is even, so add the number into total variable
• Print the sum of even number
# Python Program to Calculate Sum of Even Numbers from 1 to N

maximum = int(input(" Please Enter the Maximum Value : "))
total = 0

for number in range(1, maximum+1):
if(number % 2 == 0):
print("{0}".format(number))
total = total + number

print("The Sum of Even Numbers from 1 to {0} = {1}".format(number, total))

The output of the above program:

Please Enter the Maximum Value : 15
2
4
6
8
10
12
14
The Sum of Even Numbers from 1 to 15 = 56

Python Program to Find Sum Of Odd numbers From 1 to N

Use the following steps to find or calculate sum of odd number from 1 to n in python:

• Take the input number from 1 to that user-entered value
• Define a variable, which name total
• Iterate for loop and check each number using num%2 != 0 formula is it odd or not.
• If the number is odd, so add the number into total variable
• Print the sum of odd number
# Python Program to Calculate Sum of Odd Numbers from 1 to N

maximum = int(input(" Please Enter the Maximum Value : "))
Oddtotal = 0

for number in range(1, maximum+1):
if(number % 2 != 0):
print("{0}".format(number))
Oddtotal = Oddtotal + number

print("The Sum of Odd Numbers from 1 to {0} = {1}".format(number, Oddtotal))

The output of the above program:

Please Enter the Maximum Value : 12
1
3
5
7
9
11
The Sum of Odd Numbers from 1 to 12 = 36

Recommended Python Programs 