Lists + Functions


#1



I am a little confused with this exercise:

  1. I have a list with 3 'Fizz' items. But my code only picks up 2 ( or 1 less depending how many i put in there.)

  2. Im unsure as to what I'm doing exactly with the count variables. Could someone kind enough please explain the logic behind this and how it relates to running the code

  3. General question with codecademy. Why do some exercises not require a print statement or any return in the console so we can figure out if our code is actually correct ? For instance, here before i included my own list (and in doing so) i receive a pass for this exercise and can move on. However, the code seems wrong.

Any help greatly appreciated.


https://www.codecademy.com/en/courses/python-beginner-en-IZ9Ra/0/4?curriculum_id=4f89dab3d788890003000096


# Write your function below!
def fizz_count(x):
    count = 0
    for item in x:
        if item == "fizz":
            count = count + 1
    return count 
    
kurtis = fizz_count(['fizz', 4, 4, 'fuzz', 'fizz', 8])
print kurtis


#2

Hi if you look close to your call function

fizz_count(['fizz', 4, 4, 'fuzz', 'fizz', 8])

you will see that one is fuzz


#3

ahh man. I'm shocked i didn't recognise such a basic error. Thanks for pointing that out.

Also, i think i was a little burnt out staring at the screen. But as for my second question..

Please correct me if I'm wrong:

count = 0 essentially starts at the lowest number prior to running through the variables. So for instance, if it didn't start at 0, say 1, it would just add 1 to the actual amount of times "fizz" is in the list.

count = count + 1 refers to the integral printed in the console. As opposed to anything else (characters for example). For instance, for every "Fizz" count + 1 simply adds the value of 1 to the total which is then going to get printed in the console when the code reaches return count.


#4

count = 0 essentially starts at the lowest number prior to running through the variables. So for instance, if it didn't start at 0, say 1, it would just add 1 to the actual amount of times "fizz" is in the list.

count = count + 1 refers to the integral printed in the console. As opposed to anything else (characters for example). For instance, for every "Fizz" count + 1 simply adds the value of 1 to the total which is then going to get printed in the console when the code reaches return count.

Yes you totaly get it.