Press ESC to close

How To Find Sum of Even and Odd Numbers in Python

Photo by Pixabay

Python is a versatile and most popular programming language. It is easy to learn and always known for its simplicity and readability. This is a simple program written in python to find sum of even and odd numbers. Python programming language is mostly used for machine learning and automation. It’s widely used in various fields such as web development, data analysis, artificial intelligence, scientific computing, and automation, making it one of the most popular languages in the world today.

here's a straightforward way to add even and odd numbers separately in Python, 
# Define a list of numbers
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

# Initialize sums for even and odd numbers
sum_even = 0
sum_odd = 0

# Loop through each number in the list
for number in numbers:
    # Check if the number is even
    if number % 2 == 0:
        sum_even += number  # Add to even sum
    else:
        sum_odd += number  # Add to odd sum

# Print the results
print("The sum of even numbers is:", sum_even)
print("The sum of odd numbers is:", sum_odd)

Leave a Reply

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