Add Return Statement
00:00
I pasted a code from the exercise into the IDLE editor. So there is an on_the_shelf()
function, which contains a list named shelf_cookies
and that contains the strings, Peanut
and Chocolate
.
00:13
There is also the under_the_sofa()
function, which contains a sofa_cookies
list, and this list contains the strings Oat
and Salted Caramel
.
00:25
And then you have the cookies
list, which is currently empty, and the print()
function call, which takes cookies
. And this should print an empty list so let’s try that out.
00:39
And indeed the cookies
list right now is empty. And to actually get the cookies, we need to do a few things. One thing is currently both functions don’t return anything when we are calling the on_the_shelf()
function or the under_the_sofa()
function, None
would be returned.
01:00
However, we want the lists returned. So let’s add two return
statements with the cookies lists. I start with the on_the_shelf()
function and in the last line of the function body, I add return shelf_cookies
.
01:16
And I’ll do a similar thing with the under_the_sofa()
function. So in the last line of the function body, I add a return
statement, which returns, in this case, sofa_cookies
.
01:31 Now both functions return something, but we need to add it to the list. Let’s do this in the next lesson.
Become a Member to join the conversation.