3. Call and Response


#1

Error Message:
File "python", line 9
def square(10):
^
SyntaxError: invalid syntax

I just need help making the below function to work:

def square(10):
"""Returns the square of a number."""
squared = 10**2
print "%d squared is %d." % (10, squared)
return squared

Please help, much thanks!

`


#2

You can't set 10 as the argument it has to be a word or letter that stands as the argument.


#3

So instead of

You would execute your code like so,

#Define function with n as argument
def square(n):
    """Returns the square of a number."""
#Store n**2 in a variable named squared
    squared = n**2
#Print out a string that tells user what the number squared is.
    print ("%d squared is %d." % (n, squared))
    return squared
    
# Call the square function on line 9! Make sure to
# include the number 10 between the parentheses.
square(10)

#4

So simple. You rock!


#5

Why is it necessary to have the return squared line of code at the end of the function? I noticed that it gets the same result with or with out it present.


#6

because you created a variable squared = 10**2 and if you understand how square roots work. Return squared would be squaring the argument given. :slight_smile: