Pull it Together Error



I'm getting this error message when I try running my code: Oops, try again. trip_cost('Los Angeles', 0) returned 0 instead of the correct value 475 -- because of this error I know the problem probably lies with my function plane_ride_cost. Not sure what's going on though, I've looked through other posts and my code looks similar. Any ideas?

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): 
    cost = 40 * days 
    if days >= 7:
        cost -= 50
    elif days >= 3:
        cost -= 20
    return cost 
def trip_cost(city, days): 
    return rental_car_cost(days) + hotel_cost(days) 
    + plane_ride_cost(city)


You can verify that quite easily with plane_ride_cost('Los Angeles') - although, what could it possibly return to cause a final result of 0? If anything that suggests it wasn't used at all to arrive at 0


Hi there, so I tried compiling and running my code separately and the function plane_ride_cost would output the correct amount. It wasn't until I ran the trip_cost function that it didn't work.


So where must the problem therefore be at?

Keep in mind that you can use print statements to show values, to describe what's happening as it runs


I'm assuming it's at trip_cost, but I don't understand why.


If it's supposed to call three functions and sum up the results, then you could print out the result of each one and the sum to further narrow down where it goes wrong


Thanks for that tip! https://repl.it/F7rt/0 I did that here but again not sure why it's not summing it all up correctly. My functions are behaving but summing isn't.


Figured it out now! Thanks


+ is actually two different operators depending on whether it's used with one or two operands (similar to -)

newline ends statements unless there's some kind of continuation such as not having closed all brackets. newline can also be escaped with \, but parentheses are preferred


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