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
- Python Program to Find/Calculate Sum of n Numbers
- Python Program to Find/Calculate Average of 3, 4, 5…n numbers
- Python Program to Print ASCII Value of Character
- Leap Year Program in Python
- Python Program to Print Star Pattern
- Number Pattern Programs in Python
- Python Abs() Function: For Absolute Value
- How to Check Whether a Number is Fibonacci or Not in Python
- Python: Program to Find Power of Number
- Python Program to Reverse a Numbers
- Python Program to Find Smallest/Minimum of n Numbers
- Python Program to Find Largest/Maximum of n Numbers
- Python Program to Find The Net Bill Amount After Discount
- Python Program to Print Numbers From N to 1 and 1 to N
- Python Program to Print Numbers Divisible by 3, 5, 7
- Python Program to Print Prime Number 1 to N
- How to Find Square of Number in Python
- Python Program to Calculate Cube of Number
- Python Program to Find LCM of Two Numbers
- BMI (Body Mass Index) Calculator in Python
- Palindrome Program in Python using while loop, Function, etc
- Python: Program to Count Total Number of Bits in Number
- Python Random Number Generator Code
- Python Program to Calculate n-th term of a Fibonacci Series
- Zip Zap Zoom Python Program
- Python: program to convert Celsius to Fahrenheit
- Python Program to Swap Two Numbers
- Python Program to Get Standard Deviation
- Python Program to Find the Variance
- Python Program to Convert Height in cm to Feet and Inches
- Python Program to Convert Meters into Yards, Yards into Meters
- Python Program to Convert Kilometers to Meters, Miles
- Python Program to Find Perfect Number
- Python: Program to Find Strong Number
- Python Program Create Basic Calculator
- Python Program For math.floor() Method
- Python Program to Find Sum of Series 1/1! 2/2! 3/3! …1/n!
- Python: Program to Convert Decimal to Binary, Octal and Hexadecimal
- Python Program to Find Roots of Quadratic Equation
- Python Program to Print Alphabets from A to Z in Uppercase and Lowercase
- Python Program to Check Given Input is Alphabet, Number or Special Character