Extra money in the trip


Hi I am trying to add the extra costs to my trip but I dont really understand how to do it. Do I need to add a value or the exercise just want to train how to add another parameter?
Whats wrong with what I wrote?

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):
rental = 40 * days
if days >= 7:
rental += (-50)
elif days >= 3 and days < 7:
rental += (-20)
return rental

def spending_money(extra):
return days * 1.03

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


Hi @neriyah,

Remove the spending_money function. Instead, you need to have a spending_money parameter in the trip_cost function header rather than the extra parameter. Then you can just include the spending_money amount in the result, as follows ...

    return plane_ride_cost(city) + rental_car_cost(days) + hotel_cost(days) + spending_money


now it works but why adding the "spending_money" in the trip_cost is
sufficient? it doesnt calculate anything and its not even a function. It
doest tell python do anything so far because I didnt set any value for this
parameter no?



why would the spending_money need to calculate anything?

you simply add spending_money to calculate the total amount people would spend on a holiday, then you can supply the amount of spending money when calling the function (you do this in the next exercise)


I understand that but if I wanted to create something like

def extra_costs(extra):
trip_costs * 0.3

How would I include that in the final print so I have the right result>



Hi @neriyah,

Be aware that if you customize and submit a solution, Codecademy will probably reject it because it will not conform to the exercise instructions. However, that does not need to prevent you from experimenting.

Before suggesting an experimental solution, we need to know exactly how you would like to calculate the extra costs. Are you trying to add up all the other costs, then multiply that total by 0.3, and have the result serve as the amount of the extra costs?


yes like the trip_costs would be trip_costs * 1.03


In that case, the trip_cost function would need to be given two pieces of information in order to compute its result, namely city and days. It would not need a spending_money parameter, since the spending money would be computed and added to the total based solely on the other information.

Accordingly, you could do it as follows, but bear in mind that Codecademy will not accept this solution, because it expects the trip_cost function to accept three arguments ...

def trip_cost(city, days):
    extra_cost_factor = 1.03
    return extra_cost_factor * (plane_ride_cost(city) + rental_car_cost(days) + hotel_cost(days))

If you would like extra_cost_factor to vary, you could specify it as a parameter. Now it is up to you as the software engineer. :smile:


thanks for the answer

Best regards


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