Python function to sum even numbers in a list

Write a Python function to sum the even numbers in a list of integers.


Given a list of integers, write a Python function to find the sum of the even numbers in the list.
Example input:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Example output:


This solution is in Python. Our A.I. can create solutions in multiple languages.
by kayakane
def sum_even(list):
    sum = 0
    for i in list:
        if i % 2 == 0:
            sum += i
    return sum

print(sum_even([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]))

A.I. Evaluation of the Solution

This solution correctly finds the sum of all even numbers in the given list. It uses a simple for loop to iterate through the list, checking if each number is divisible by 2 (i.e. is even), and if so, adding it to the running total. This is a straightforward and effective solution.

Evaluated at: 2022-11-20 06:16:26