Wats wrong it s not printing eggs!?


#1


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.


#2

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 ...

spam()

#3

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.

spam()


#4

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


#5

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.


#6

# 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!"
    """ prints Eggs! on console"""

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

#7

still showing error it says that u have 2 print eggs


#8

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

spam()

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.


#9

yes i do still not printing


#10

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 ...

spam()

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


#11

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


#12

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

#13

wat format u usedfor printing ????


#14

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.


#15

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


#16

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.


#17

also functions seems bit confusing as of now


#18

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.


#19

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


#20