This code won't run on codecademy but run on python (GUI)


#1



Replace this line with your code. 

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


#2

print count is unreachable code. You return something above it. The better option is to print fizz_count(list) outside your fizz_count() function.

def fizz_count(x):
    count = 0
    for item in x:
      if item == "fizz":
        count = count + 1
    return count
    
print fizz_count(list)

#3

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

It says returned 1 instead of 2


#4

If you print x, you're just printing out the same thing you put into the function. Nothing actually happens.

Take a look at this code:

list = ["fizz","buzz","fizz"]

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

print(fizz_count(list))

It's the same as yours... It goes through a list, and each time it finds the string "fizz", it adds 1 to count. Then, when it is done with the list, it returns that count. Finally, outside the function, it prints the result of that function; what it returns. In this case, count.


#5

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