Coding Quiz
This coding quiz is about writing a function that returns the sum of even numbers from a given list.
When given a list of integers
, write a function to calculate and return the sum of the even numbers in the list.
Sum of Even Numbers
def solution(numbers): return # Write your code here
Hint
-
In Python, you can use a
for loop
to iterate through a list. -
To check for even numbers, use the
% operator
. An even number will havea remainder of 0
when divided by2
. -
Use the
return
keyword to return the result.
Use the knowledge you’ve gained to write a function that calculates and returns the sum of even numbers and check if it passes the test.
Example Input and Output
Example 1
-
Input: [1, 2, 3, 4, 5, 6]
-
Output: 12
Example 2
-
Input: [10, 15, 20, 25, 30]
-
Output: 60
Lecture
AI Tutor
Publish
Design
Upload
Notes
Favorites
Help