There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
You can also find further discussion and get answers to your questions over in Language Help.
Agree with a comment or answer? Like () to up-vote the contribution!
I thought this exercise was a little basic, so I had fun modifying it.
Here’s a alternate way to make use of lists and the len() function:
# This function will print a hardcoded count of how many locations we have.
favorite_locations = ["Paris", "Norway", "Iceland"]
def print_count_locations():
length = len(favorite_locations)
print("There are " + str(length) + " locations.")
# This function will print the favorite locations
def show_favorite_locations():
print("Your favorite locations are: " + str(favorite_locations) + ".")
print_count_locations()
show_favorite_locations()
I am not following why I didn’t have to define the locations?
From the previous lessons I was under the impression that all:
def anything_before_the_parameter(p1, p2, p3) - needed to be defined.
So my first thought was to add parameters.
So now looking at the code solutions it was defining variable before the parameter which didn’t need to be defined at all?
Was it predefined in the code for the exercise? All previous exercises in this lesson has parameters and arguments being utilized.
Outer scope is accessible for read-only, but yes, we can call anything, whether function or variable. If it doesn’t exist in that scope then a ReferenceError will be raised.
def main():
def foo():
x = a * b
return x
def bar():
y = a + b
return y
a, b = 6, 7
return foo(), bar()
Above both foo and bar can see a and b. They can’t see each other’s local variables, x and y, and neither can they be seen from the scope of a and b.
It wasn’t immediately obvious what I needed to do here. I made an empty string for the variable so that both functions could access it, but kept running into a wall before realizing I needed to copy the string from inside one function and define it in the variable outside of them. Might help to re-write instruction 2 so that it’s a little more clear what to do here. I understood what I needed to do and it took me far longer than I care to admit how to advance to the next section.