Close Circle Icon
This forum is now read-only. Please use our new forums at discuss.codecademy.com.
0 points
Submitted by Jillian
6 years ago

How do I call a function in the argument of another function?

Hi all, The code below gets me through the lesson, but I have a feeling that this was not the way I was supposed to put the code together. deserves_another should be defined so it always adds 2 to the output of one_good_turn? How would I write that?

 def one_good_turn(n):
        return n + 1
 def deserves_another(n):
        return n + 3

This doesn’t work…

def one_good_turn(n):
    return n + 1

def deserves_another(n):
    return one_good_turn + 2

Answer 53a4647d80ff333a19000753

0 votes

Permalink

Never mind… so this works

def one_good_turn(n):
    return n + 1

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

I don’t understand how my first code passed through the lesson if it doesn’t perform the subject of the level though? How does the lesson determine what code passes and what doesn’t?

201 points
Submitted by Jillian
6 years ago

3 comments

Corey Gibbons 6 years ago

I just found your answer while searching for the same thing, I wanted to say though I have been having the same problems with passing lessons I know are not correct so when I get that I just google it. also a good thing to have is python and idle open with your lessons so you can fact check in a real shell.

Corey Gibbons 6 years ago

hmmm to add to that my IDLE shell is telling me I have an invalid syntax with the code you posted (although it did get me through the lesson too lol)

bobbymagee 6 years ago

Many thanks,Jillian,