Pull it together Please help!


Below your existing code, define a function called trip_cost that takes two arguments, city and days.
Like the example above, have your function return the sum of calling the rental_car_cost(days), hotel_cost(days), and plane_ride_cost(city) functions.
It is completely valid to call the hotel_cost(nights) function with the variable days. Just like the example above where we call double(n) with the variable a, we pass the value of days to the new function in the argument nights.

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 * cost
if cost >= 7:
rent += 50
elif cost >= 3:
rent += 20
return cost

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

Oops, try again. rental_car_cost(1) raised an error: global name 'cost' is not defined



rent = 40 * cost

cost is undefined, where do you think you defined it? the rent is 40 times the number days, then you should check how many days the car is rented and see if you need to give discount


Hi muska31,

If you don't understand the error message, i can translate it for you:

You have a bug in the function rental_car_cost. The bug is that you have used a variable 'cost', which you have not defined.

Look in the function rental_car_cost:
It looks like you have mixed the three variables: 'days', 'rent', and 'cost'.
Your argument is called 'days', but it is not used in the block.
It looks like you have used it correctly, but in the name cost. Do you understand?
So, the places where you have typed 'cost', you should type days instead, except for the bottom line.
In the bottom line, you have returned the wrong variable; you have returned the days instead of returning the total of money being spent in the rental car. You have called the total 'rent', so you need to return that instead.
A last thing is (I can say this because i've made the exercise):
You've made a typo in these two lines:
rent = 40 * cost
if cost >= 7:
rent += 50
elif cost >= 3:
rent += 20
return cost

It was meant to be a discount, but you have made it an extra tax! :grinning:

So if we gather the threads, you should (inside the function rental_car_cost):

  • Replace cost with days in the code block, except for the bottom line
  • Return your 'total' variable, which is here called 'rent'
  • Change + to - in the two lines with 'discount'

Hope this will help you.


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