Plan Your Trip! Seriously CANNOT Print the Cost!


Okay, so I've been stuck on this for a few days now. I'm trying to print the cost of my trip, and I'm almost positive I've done everything right. However, when I submit my code, it tells me that there's been an error and asks if I deleted the trip_cost function, (which I didn't do.)

According to what I know, the code should be printing the cost of the trip given the arguments that I defined at the end, but for whatever reason it seems to be getting confused. Can anyone help me please? I'm getting really frustrated with this.

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 trip_cost(city, days, spending_money):
    return rental_car_cost(days)+hotel_cost(days)+plane_ride_cost(city)+spending_money
    print trip_cost("Los Angeles", 5, 600)


a function only executes when called, so the function call should be outside the function (hint: indention, or rather, no spacing in this case) to place the function call outside the function


That makes sense, but does the print command not call the function? Or do I need to do something else after the print command in order to call the function?


You could asign the result of calling trip_cost to a variable and then print that variable.

x = trip_cost("Los Angeles", 5, 600)
print x


It's still asking me if I deleted the trip_cost function whenever I submit my code, and I don't know exactly what it means when it asks that. I'm sorry to be such a bother.


this is the function call:

trip_cost("Los Angeles", 5, 600)

print will make sure the returned result will be printed. But the whole line should be indented differently so the function call (and print) are outside the function


It's cool. Right here the indentation is wrong when calling "print trip_cost", see? You're still inside the trip_cost definition. Your print command does print it, yeah.


Okay, so this is what I have so far.

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

trip_cost("Los Angeles", 5, 600):
print trip_cost

I think the indentations are correct, but I'm still getting the error message "Oops! Did you accidentally delete the trip_cost function?"
I've even tried indenting the print trip_cost command one more time than it already is, and I still get the same error message.


The indentation here is not helping lol.

It's really easy:
print trip_cost("Los Angeles" etc)

should not be indented at all. No spaces. Otherwise you're still inside the previous definition. Check carefully where your previous definition begins and ends.


Ohh okay, I get it now. I feel really dumb lol. I was getting confused for some reason and thinking that the indent meant the print function was outside the defined function, instead of vice versa. My bad. Thanks for the help!