Mode_of_transportation not defined?

I am trying to complete the roundup at the end of the introduction to functions module, but it is saying that the mode_of_transport is not defined, even though I thought I had defined it already?

Where is it defined? Keep in mind that a variable definition would look something like this.

my_value = 'potato'

Note: It would be very helpful if you copy your code, and paste it into a reply rather than using a screenshot.

Hint

Your confusion seems to be related to scope. A parameter of a function that is assigned to a default value is locally scoped to the function. A variable that happens to share the same name in another scope is not assigned to the same value as the function’s parameter.

To use the default value of a parameter, you simply don’t provide an argument for that parameter in the function call.

def times_two(num=5):
  return num * 2

#provide an argument
print(times_two(12)) # 24
#provide no argument (use the default value)
print(times_two()) # 10
1 Like

if having mode_of_transport = "Car" in the function def as the instruction say is not actually needed then why is that what it says in the instructions?

If you want a default value in your parameter list, it is needed. The error you had is a result of a variable that happens to share the same name as a function’s parameter having no definition prior to its attempted use.

In the scope of your function call:
(This is why I asked for you to post your code. Re-typing code from a screenshot is kind of a pain.)

destination_setup("The USSR", "Lapland", estimate, mode_of_transport)

mode_of_transport is undefined. The fact that you have a function parameter with the same name is inconsequential. They are not references to the same value. They exist in separate scopes.

To add to my previous example,

def times_two(num=5):
  return num * 2

#provide an argument
print(times_two(12)) # 24
#provide no argument (use the default value)
print(times_two()) # 10
some_num = 12 # some_num defined
print(times_two(some_num)) # 24
#try an undefined variable
print(times_two(num)) # NameError: name 'num' is not defined