Call and Response 3/19


#1

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.
square(10)

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

Regards.


#2

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.


#3

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.


#4

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


#5

Thank you so much!!!


#6

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