Hey, You Never Know!



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?


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,


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.


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?


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.


That makes sense, thanks!


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