Sum of Even Numbers in a List of Integers

Given a list of integers, this Python function will find the sum of the even numbers in the list.

Problem

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:
30

Solution

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: 2023-01-27 16:28:44