pythonbeginner7 minutes
Count Even Numbers
Count how many even numbers appear in a list.
Challenge prompt
Write a function called count_even_numbers that receives a list of integers and returns how many of them are even.
Guidance
- • Loop through each number in the list.
- • Check whether the number is divisible by 2.
- • Increase a counter when the number is even.
Hints
- • Use the modulo operator.
- • You can start a counter at 0.
Starter code
def count_even_numbers(numbers):
# your code here
passExpected output
count_even_numbers([1, 2, 3, 4, 6]) should return 3.
Core concepts
loopsconditionalslists
Challenge a Friend
Send this duel to someone else and see if they can solve it.