Rename the Palace Return Address
00:00
Here you can see the code that we’ve had in one of the former lessons in the IDLE editor. So it’s the explore_basement()
function with the explore_cabinet()
function inside with the mouse
docstring.
00:15
There is also the global address
keyword and on the bottom of the file you have address = "Python Palace"
, that’s a string, the explore_basement()
function call and the print()
function call of the address
variable.
00:30 To revisit how this code works, let’s save and run the code, and then you have the output from the solution before which says “Cookie Cabinet”, “Mouse House” and “Cookie Cabinet”.
00:43
Now let’s take some learnings from the former lessons into this one. You know that a function without a return statement returns None
, but you actually want to use “Mouse House” for the last print()
function call.
00:57
So what you can do is add return address
into the last line of the explore_basement()
function,
01:06
and then you need to collect the return value somewhere. So instead of just calling explore_basement()
in line 14, you can write it into a variable.
01:16
For example, you can use the same variable name again, which is address
. So this line is address = explore_basement()
and when you save and run the code, you get “Mouse House” as the last print()
function call.
01:34 And while it solves the exercise, I want to do a little bit of cleanup.
Become a Member to join the conversation.