Function Junction


#1



why wont this work


'''Prints '''Eggs!' to the console.'''
# Define the spam function above this line.
def spam("Eggs!"):
print spam


#2

The function you are attempting to define is empty, as in it has no commands to execute.

Fortunately, this is function requires no arguments so it is a bit easier:
Define the function:

def function_name():

Tell the function what you need it to do (note, this should be indented so as to be inside the function):

    print "something"

And finally call the function in order to execute it:

function_name()

#3

Problem

'''Prints '''Eggs!' to the console.'''
# Define the spam function above this line.
def spam("Eggs!"):
print spam

Why does not it work ?
It does not work because it has indentation error.
It does not do what the problem told us to.
It should be:

'''Prints '''Eggs!' to the console.'''
# Define the spam function above this line.
def spam():
   print "Eggs!"

spam()  # calling the function

When a new block starts we put 4 spaces there.

a small article on importance of Indentation


#4

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