Quotes help make search much faster. Example: "Practice Makes Perfect"

Sunday, November 25, 2012

Codecademy: "Function Junction"


#sample solution


def spam():
"""Prints 'Eggs!' to the console."""
print "Eggs!"

spam()

2 comments:

  1. thanks this worked. just a question, why did you need the last line spam()? why wouldn't it print Eggs! with just the top three lines?

    thanks

    ReplyDelete
    Replies
    1. Re-usable code is an important concept in programming. The first three lines are what's called a "function" in some programming languages. Once you have defined a "function", you can just call it by using it's name, in this case, "spam()". So everytime you want to make use of the function, you could just type spam(). If you were to create a game and you want a ship to shoot lasers everytime you pressed a button, you can create a function called shootLasers(). That way, you don't have to define or re-write multiple lines of code everytime the button is pressed. You just call the function shootLasers() each time.

      Delete


This is an example of scrolling text using Javascript.

Popular Posts