Error in creating function spam()


Oops, try again. Make sure your function prints "Eggs!" to the console!

I can't understand whats wrong with the code

def spam():
    """Prints 'Eggs!'"""
    print "Eggs!"


Once we define / make our function, To use that function we need to call it.

Like this..

suppose a function is here..

def ACoolFunction():
    print "some cool thing"

Now, How to call this function ?

simple, name of function and (),with parameter(s) (if it has any)


In ahead of section, You will come across function(s),That returns a value and does not just prints things, so you may need to save the call-value in some variable.


How can the console print "Eggs!" if my function is "spam ()"? . I don´t understand that, please help. I understand, perfectly, your example and the codecademy's example...


hello @nayelilv

function is nothing but a wrapper with a name on it,
It wraps code lines that is going to repeated in a big program.
When we call the function by its name and with the data(parameter/argument) its needs(you will learn more about function that needs data in next exercises).
The function simply runs the code inside of it.

Like in this example when we call the function, it simply checks what lines of code there(inside of function) and runs it, as you can see function have one line of code that prints a string so we have string printed in console.


def spam():

prints something

print "Eggs!"


But it doesnt work why?


def spam():

prints something

print "Eggs!"

Define the spam function above this line.


this does not work as well


hi @bitninja23259
Make sure you indented the code lines inside the function carefully,
like this...

def some():

Can you see I made 4-spacebars space there ?
to call this function,I'd do this.



I already solved it, but there are defined only very narrowly defined
solutions ..if you print no eggs but somethiing else it does not work...but
point in learning should be so that you should understand process not that
ther eis only printed eggs....
Thanks you anyway:)


Oh yeas CC is quite strict towards instruction following and in this exercise it mentioned what to print ("Eggs!"), so it won't work for any other string but in general it does work!


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