Sum of integers divisible by 3

This problem asks the user to write a function that takes in a list of integers and returns the sum of the integers that are divisible by 3. An example input and output are given.

Problem

Given a list of integers, write a function that returns the sum of the integers that are divisible by 3.
Example input:
[1, 2, 3, 4, 5, 6, 7, 8, 9]
Example output:
18

Solution

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

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

A.I. Evaluation of the Solution

The candidate's solution correctly solves the problem. They iterate through the list and add the numbers divisible by 3 to a sum variable. They then return the sum variable. This is a solid solution that is easy to understand.

Evaluated at: 2022-11-21 08:16:32