# List + Functions: Lesson Question

#1

INSTRUCTION: After the loop, please return the count variable.

I don't understand the purpose of "return count" after my if statement
why can't I write

if variables == "fizz":
count = count + 1
else:
return count

``````def fizz_count(x):
count = 0
for variables in x:
if variables == "fizz":
count = count + 1
return  count``````

#2

Because if you return count inside an if/else statement, then it will only return if that condition is met. The way your saying it would not return the count if variables == "fizz"

#3

so, what I'm getting now is

this code alone will give me 0 if I print fizz_count(["fizz"]), will also give me 0 when print fizz_count(["fizz", "fizz"])

def fizz_count(x):
count = 0
for variables in x:
return count

however when this if code is inserted print fizz_count(["fizz", "fizz"]) it becomes 2 ?
if variables == "fizz":
count = count + 1

#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.