# Pull it Together Error

#1

https://www.codecademy.com/en/courses/python-beginner-P5YtY/1/4?curriculum_id=4f89dab3d788890003000096#

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)``````

#2

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

#3

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.

#4

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

#5

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

#6

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

#7

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.

#8

Figured it out now! Thanks

#9

`+` 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

#10

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