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

  1. Python Program to Find/Calculate Sum of n Numbers
  2. Python Program to Find/Calculate Average of 3, 4, 5…n numbers
  3. Python Program to Print ASCII Value of Character
  4. Leap Year Program in Python
  5. Python Program to Print Star Pattern
  6. Number Pattern Programs in Python
  7. Python Abs() Function: For Absolute Value
  8. How to Check Whether a Number is Fibonacci or Not in Python
  9. Python: Program to Find Power of Number
  10. Python Program to Reverse a Numbers
  11. Python Program to Find Smallest/Minimum of n Numbers
  12. Python Program to Find Largest/Maximum of n Numbers
  13. Python Program to Find The Net Bill Amount After Discount
  14. Python Program to Print Numbers From N to 1 and 1 to N
  15. Python Program to Print Numbers Divisible by 3, 5, 7
  16. Python Program to Print Prime Number 1 to N
  17. How to Find Square of Number in Python
  18. Python Program to Calculate Cube of Number
  19. Python Program to Find LCM of Two Numbers
  20. BMI (Body Mass Index) Calculator in Python
  21. Palindrome Program in Python using while loop, Function, etc
  22. Python: Program to Count Total Number of Bits in Number
  23. Python Random Number Generator Code
  24. Python Program to Calculate n-th term of a Fibonacci Series
  25. Zip Zap Zoom Python Program
  26. Python: program to convert Celsius to Fahrenheit
  27. Python Program to Swap Two Numbers
  28. Python Program to Get Standard Deviation
  29. Python Program to Find the Variance
  30. Python Program to Convert Height in cm to Feet and Inches
  31. Python Program to Convert Meters into Yards, Yards into Meters
  32. Python Program to Convert Kilometers to Meters, Miles
  33. Python Program to Find Perfect Number
  34. Python: Program to Find Strong Number
  35. Python Program Create Basic Calculator
  36. Python Program For math.floor() Method
  37. Python Program to Find Sum of Series 1/1! 2/2! 3/3! …1/n!
  38. Python: Program to Convert Decimal to Binary, Octal and Hexadecimal
  39. Python Program to Find Roots of Quadratic Equation
  40. Python Program to Print Alphabets from A to Z in Uppercase and Lowercase
  41. Python Program to Check Given Input is Alphabet, Number or Special Character

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *