5/7 Argument Order


#1

Hi,
Can someone please explain why the order of the arguments/variables is important in this example (and/or in general)?
In this case its simply the "city" and the "days" arguments:

e.g.1 - this Doesn't work:

def trip_cost(days,city):
return rental_car_cost(days) + plane_ride_cost(city) + hotel_cost(days)

e.g.2 - this Does work:

def trip_cost(city,days):
return rental_car_cost(days) + plane_ride_cost(city) + hotel_cost(days)

Many thanks for any help / explanation...


#2

As long as you call your function with parameters in the right order - it does not make a difference.

The problem is not related to Python, it's part of codecademy interface.

As you probably noticed, when you click Save & Submit Code codecademy tests your code against some rules. They have to do this because they want to give you the best possible error message in case of any problem with your code. We talk here about problems like a wrong order of calculation, wrong type of returned data (for example because 2 / 4 is 0, not 0.5) etc. Problems that are more subtle than normal syntax errors (which will be noticed by Python interpreter).

This is a positive aspect of codecademy - you don't have to spend many hours checking your code line by line to find a bug. You usually get an error message that is implying a ready to use fix. The negative side of this interface is that you have to carefully follow instructions. Why order is important? Because they test your function by calling it with city as a first parameter and days as a second.


#3

Thanks a lot for your reply.. however I still don't understand (my fault; I'm new to Python and coding in general).

As I see it, the "trip_cost" function returns a value from another function ("rental_car_cost") which uses "days" argument first (not the "city" argument), so I still don't understand why the order must be as it is..(with "city" as argument 1 in the trip_cost function).


#4

Factoradic - I just re-read your post: the second line sums it up: so in Python (in general) the argument listing order doesn't matter - it is only a (useful) aspect of Codecademy where it does matter; for learning purposes, as you mentioned.


#5

Exactly :smile: Sorry, I am still learning English and sometimes it's hard for me to write down my thoughts.