Hey, You Never Know!


#1



https://www.codecademy.com/en/courses/python-beginner-P5YtY/1/5?curriculum_id=4f89dab3d788890003000096


When doing this problem, I came across this question: does the order of arguments taken in functions matter? Because apparently my code below results into an error: "cannot concatenate 'str' and 'NoneType' objects".


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


If I switch "days" and "city" it would work. Could someone explain this?


#2

Yes, order matters. The parameters have no special meaning, but the order of the arguments does.

def trip_cost(city, days, spending_money):

The call,

trip_cost("Charlotte",9,500)

With the reversal of days and city in your function, days is a string, and city is a number. That's where the error crops up.


#3

Hmmm, I still don't get why order matters. In that particular problem, I didn't call anything, it wasn't until the next problem that the instruction gives me the details of the call. Is the system setup assuming anything?


#4

The lesson checker might have sent a call. That would throw an error if the string is passed first but stored in days.

Order is determined by the caller, not the callee. It doesn't matter what the local variables are named, they will receive the values in the order they are sent.


#5

That makes sense, thanks!


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.