Wats wrong it s not printing eggs!?


Define your spam function starting on line 5. You

can leave the code on line 11 alone for now--we'll

explain it soon!

def spam():
return "Eggs!"

Define the spam function above this line.

print spam()
""" prints Eggs! on console"""

Replace this line with your code.


Hi @betapro46803,

The instructions specify this ...

Go ahead and create a function, spam, that prints the string "Eggs!" ...

Use print in the function code, instead of return.

Then, to call the function, you only need ...



If you still need help with this, This code will pass it:

Define your spam function starting on line 5. You

can leave the code on line 11 alone for now--we'll

explain it soon!

def spam():
print "Eggs!"
"""python is harder than ruby"""

Define the spam function above this line.



y cant we use return and then call spam???


The instructions ask to have the function print the string "Eggs!". However, if Codecademy's submission correctness test (SCT) for this exercise allows you to have the function return "Eggs!", instead, then it is fine to do it that way.

Are you getting an error message? If so, let us know what it is so we can help resolve the issue.


# Define your spam function starting on line 5. You
# can leave the code on line 11 alone for now--we'll
# explain it soon!

def spam():
    """ prints Eggs! on console"""

# Define the spam function above this line.                          spam()


still showing error it says that u have 2 print eggs


Do you have this line in your code? ...


That should call the function so that its code executes.

Put that function call on its own line, and be sure not to indent it.


yes i do still not printing


In this post, you have this line ...

# Define the spam function above this line.                          spam()

That entire line is a comment that ends with spam(). Since the line is a comment, none of the code on that line executes.

Create a line that has only this on it, and make sure it is not indented ...


If your submission still does not pass, post all of the code again, and we'll take another look at it.


thx its done but wats the meaning of return with ref to functions????


The purpose of including a return statement in a function is generally to enable the function to make a result available for a program to use. For example, the len built in function returns a result that indicates the number of characters in a string or the number of items in a sequence such as a list.

A programmer who creates a function might choose to include a return statement in the function rather than only a print statement so that a programmer who uses the function could save the result of calling it in a variable.

Below is an example of a function that computes and returns compound interest. After the function definition are two function calls with assignments of the results to variables.

def principal_with_interest(p, r, n, t):
    # p: the initial principal
    # r: annual interest rate percent
    # n: number of times annually that interest is compounded
    # t: number of years that the money is invested
    return p * (1.0 + float(r * 0.01) / n) ** (n * t)

money_in_five_years = principal_with_interest(10000.00, 4.0, 12, 5.0)
money_in_ten_years = principal_with_interest(10000.00, 4.0, 12, 10.0)

print("Five years: ${:0.2f}".format(money_in_five_years))
print("Ten years:  ${:0.2f}".format(money_in_ten_years))

Output ...

Five years: $12209.97
Ten years:  $14908.33


wat format u usedfor printing ????


Python offers a format method that can be used with strings. The above example uses it here ...

print("Five years: ${:0.2f}".format(money_in_five_years))

See Python: str.format(*args, **kwargs) for official documentation of that method.

The format method is accompanied by a Format Specification Mini-Language that is very detailed. The documentation might seem a little abstract, so a good means of learning about it would be to Google Python Format Specification Mini-Language or something similar to search for examples of how it can be used in programs.


it'd take yrs of practice how long does it take???


Well, it's not necessary to try to memorize all of it; that might take up a lot of time that would be best to devote to learning other things. Instead, start by choosing a few features of the Format Specification Mini-Language that seem interesting to you, and try them out in some code. You'll probably remember the features that are most interesting to you. Many programmers are happy to look at the documentation when they need to do something that is new to them instead of trying to memorize it all.


also functions seems bit confusing as of now


Many of the upcoming exercises use functions, but most of them are not very complicated. Those exercises will give you a chance to practice, and one of the likely outcomes is that functions will become less confusing.


A post was split to a new topic: Review: Built-In Functions