Pulling it Together


#1

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):
cost = days *40
if days >= 7:
cost = cost - 50
return cost
elif days >= 3:
cost = cost - 20
return cost
else:
return cost;
def trip_cost(city, days):
spending_money=600
return plane_ride_cost(city)+hotel_cost(days)+ spending_money
That is my code and I am not getting any console errors it just says "Trip_cost must be in the 3 parameters, city, days, and spending money.Must be in that order. I am new to code and the language so some help and an explanation would be useful


#2

I urge you to take a look at this post, if you need help with code and this forum. It will help people like me who are trying to help you out, a lot. I'll get to see how you've indented your code, which is extremely important.

Also, from what i see your code looks pretty good. Except for the last two lines. The instructions in this session are pretty straightforward. Take a look at them again and at your code again. You should be able to see your mistake.


#3

Thanks for the quick reply. I redid the last two lines and just did what it asked but got an invalid syntax error for def trip_cost('Los Angeles', 5, 600):

def hotel_cost(days):
    return 140*days
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):
    cost = days * 40
    if days>=7:
        return cost - 50
    elif days>=3<7:
        return cost -20
    return cost
def trip_cost('Los Angeles', 5, 600):
    print trip_cost

#4

Hi, @rafael.piloto ,

This will not work as a function header ...

def trip_cost('Los Angeles', 5, 600):

@ronybot was correct in that the problems with your original code were in the final several lines. However, the particular changes you made in response introduced additional problems.

The problem in your original code, here ...

def trip_cost(city, days):

... was that you were missing the spending_money parameter.
With that parameter added to the header, you should remove this statement ...

spending_money=600

Then, outside the function definition, you need to call the function to get it to execute, as follows ...

print trip_cost('Los Angeles', 5, 600)

The values for the parameters are set by the arguments that you pass when you call the function, as in the above statement.


#5

Oh, ok I see where I made my mistake. It was so simple and yet it took me a while. I am pretty new so thanks for the explanation. I adjusted my code and it ran perfectly. Thank you so much for your help.


#6