Why is my count incorrect?


#1

Question

Why is my count incorrect?

Answer

A common issue is returning at the wrong place in your code. Be sure you don’t use return inside of a loop or the loop will only run one time, depending on where inside the loop you wrote it.
Remember: as soon as a function executes a return statement, it exits immediately and returns that value to wherever the function was called in the program.
In the count() function, we want to return at the end of the function, after we loop through the list provided, so our return should be indented only once with two spaces.


FAQ: Learn Python - Practice Makes Perfect - count
#2

3 posts were split to a new topic: Count function with list