Lecture
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 loopto iterate through a list. -
To check for even numbers, use the
% operator. An even number will havea remainder of 0when divided by2. -
Use the
returnkeyword 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
Lessons in this chapter · Concepts of Functions, Modules, and Packages
- 1. Code Blocks Performing Specific Tasks, Functions
- 2. Components of a Function
- 3. What Does It Mean to Call a Function?
- 4. Keyword Arguments and Variable Scope
- 5. Simplifying Functions with Lambda Functions
- 6. Fill-in-the-blank quiz
- 7. Introduction to Files and Basic Input/Output
- 8. How to Read File Contents
- 9. How to Write Data to a File
- 10. Exception Handling for Writing Safe Code
- 11. Enhancing Code Reusability and Efficiency with Modules
- 12. How to Create Your Own Python Modules
- 13. What Are Packages and How to Use Them?
- 14. Multiple-choice quiz
- 15. Coding Quiz - Sum of Even Numbers
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help