Testing my function


#1

https://www.codecademy.com/courses/learn-python/lessons/functions/exercises/functions-calling-functions?action=resume_content_item

Hi, I’m trying to test my function named deserves_another. Why is it not printing to the console?

def one_good_turn(n):
  return n + 1
    
def deserves_another(n):
  return one_good_turn (n) + 2
  print deserves_another
  
deserves_another(10)

#2

return is a last thing a function does, so the return keyword will “end” the function, so the print statement is never reached

don’t you want to print the returned result by placing a print statement before calling deserves_another (last line of your code)?


#3

I tried to test my function by trying to print to console, but my won’t work. What am I doing wrong?

def one_good_turn(n):
return n + 1

def deserves_another(n):
return one_good_turn(n) + 2

print deserves_another
deserves_another(10)

The following won’t work either:_____________________________________________________

def one_good_turn(n):
return n + 1

def deserves_another(n):
return one_good_turn(n) + 2

deserves_another(10)
print deserves_another


#4

https://www.codecademy.com/courses/learn-python/lessons/functions/exercises/functions-calling-functions?action=resume_content_item

I think I got it. Please let me know if there are easier alternatives, which I could be missing:

def one_good_turn(n):
return n + 1

def deserves_another(n):
return one_good_turn(n) + 2

deserves_another(10)
print deserves_another(10)


#5

you already have the function call:

deserves_another(10)

why is it so difficult to put a print statement in front of it? Remember, calling the function requires parentheses, and given your function has a parameter, you also need an argument

its fine now


#6

Is it “better” or more proper to keep the print statement in front of the call function? Thanks for working this through with me


#7

in programming, there aren’t absolutes. print statements within the function are sometimes also possible and fine.

but if you print and return the same result within the function body, you should move the print statement to the function call


#8

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