Putting it all together: Must call variables in order introduced in code


Getting error after error on the end of Exercise 2.4 "Pull It Together"

After chatting with a Pro user, I learned that you must call variables in the order in which they are introduced in the code.

So, in the vacation calculator

def trip_cost(days, city):

Will give you an error. While:

def trip_cost(city, days):

Will work just fine.

Since the exercise asked you to use "days" instead of the variable "nights" originally used to calculate hotel cost, I had switched the order. Spent a solid hour trying to figure out what I'd done wrong.


What is the question? Yes, given you work with positional arguments the parameters should be in the right order


you are kidding me right?

The answer you need is in this topic, the arguments are positional, so the parameters need to be in the right order (i mentioned this) and the answer you need is even there:

the answer is literally in front of you.....


def hotel_cost(nights):
return 140 * nights

def plane_ride_cost(city):
if city == "Charlotte":
return 183
elif city == "Tampa":
return 220
elif city == "Pittsburgh":
return 222
elif city == "Los Angeles":
return 475

def rental_car_cost(days):
rent = 40 * days
if days >= 7:
rent -= 50
elif days >= 3:
rent -= 20
return rent
def trip_cost(city, days):
return sum(rental_car_cost(days) , hotel_cost(days) , plane_ride_cost(city))

above is my code idk y its not working pls helpppppp


sum() expects an iterable like a list, to get the sum of the integers returned by the function calls we can use basic math operator named plus sign (+)


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