5-7 Help


#1

When I submit the code below, it tells me that i need to make sure that i defined a variable named trip_cost. I don't understand this because I do have trip_cost.

def hotel_cost(nights):
return 140 * nights

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

def rental_car_cost(days):
if days >= 7:
return (days * 40) - 50
elif days >= 3:
return (days * 40) - 20
else:
return days * 40

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

#2

Hello! Could it be asking for a variable, like:

trip_cost = (return rental_car_cost(nights) + hotel_cost(days) + plane_ride_cost(city))

rather than a function? I know sometimes the autocoder is particular about the way in which you specify data.

I also noticed that the trip_cost function doesn't have nights as a parameter: Could that be the issue?

Good luck!


#3

According to the instructions, the trip_cost function should have city and days as the parameters, but I don't remember it saying anything about using nights in it.


#4

Hmmm. What if you add nights as a third parameter?

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

Does it recognize it then?


#5

No, it has the same error.


#6

I went to look at how I did it, and there were two differences from yours: the return value was all in parenthesis (which I don.t think makes a difference), but more importantly rental_car_cost takes days as a parameter, not nights. Could that be the issue?

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

#7

no, it still has the same error.
Is the trip_cost function supposed to turn red within the code, because mine doesn't.
Also, how do you make the code look like it's original format when putting it in a reply?


#8

I forget if trip_cost should change colors. I think it might. But to a question I can answer: :wink:

To reprint your code in formatted fashion, just put three accents ` (to the left of the 1 key, under the ~ ) before and after the code you want to format.

Also, check out this website : python tutor for testing code You can paste in your code, hit 'Visualize Execution', and it will show you what's happening at each step of the program. Sorry I couldn't help you more. Good luck!


#9

Thanks for your help!


#10

def hotel_cost(days):
return 140 * days

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

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