Call and Response 3/19


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

Call the square function on line 10! Make sure to
include the number 10 between the parentheses.

Can someone please explain why, there is return squared on line 5 .
What is it for?



the exercise is named call and response, which is very appropriate.

function give a response, they return something/the function hands you something back

in this case squared, now we can use this returned value if we want.


Thank you.But in 4/19,there is no return result on line 4:

def power(base, exponent): # Add your parameters here!
result = base ** exponent
print “%d to the power of %d is %d.” % (base, exponent, result)

power(37, 4) # Add your arguments here!

I don’t know when I should add the return statement.


then the function returns a default value (None)

there isn’t one definitive answer to that question, that depends on the program you implement and design choices you make. You will learn as go along


Thank you so much!!!


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