What is wrong with the functions course? (python)


#1

def hello_world():
"""Prints 'Hello World!' to the console."""
print "Hello World!"


this is copy and pasted code from the lesson that I threw into the compiler and it didn't print anything. I then tried just the header part of the function and got this error: "unexpected EOF while parsing". I know I'm a moron for not even being able to write a basic function in python, but I just need information about this issue.


#2

For your function to work it should be indented like this,

def hello_world():
    """Prints 'Hello World!' to the console."""
    print "Hello World!"

#3

Hi, @codingeinstiensface ,

See @bandit's reply regarding the indentation. When you post code, be sure to format it, so that we can see how it is indented. For instructions on how to format posted code, consult How do I format code in my posts?.

After you have defined your function, you must call it, if you would like to it execute. Since you did not call your function, nothing got printed. In order to call your hello_world function, add the following line to your code ...

hello_world()

Be sure not to indent that line, otherwise it will become part of the function definition.


#4

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