What is wrong with may calculation? (Oops, try again. trip_cost('Charlotte', 1) returned 180 instead of the correct value 363)

#1

Pull it Together

Oops, try again. trip_cost('Charlotte', 1) returned 180 instead of the correct value 363

``````Replace this line with your code.

def hotel_cost(nights):
nights *= 140
return 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
else:
return 0

def rental_car_cost(days):
rent = days * 40
if days >= 7:
rent -= 50
elif days >= 3 and days <=6 :
rent -= 20
return rent

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

#2

Hello @hellocole11,

Can you please post your code, a link to the exercise you are stuck on, and the error message you're getting... Thanks!

#3

sorry forgot to add my codes and the details.

#4

I think on line

elif days >= 3 and days <=6

it should actually be

elif days >= 3 and days <7

#5

Thanks for the reply, but im pretty sure its the same coz' <=6 is any numbers that is less or equal to 6 and the <7 is any number that is less than to 7 but not equal to 7.

#6

Try switch ' to " as that tends to work sometimes for an unknown reason. You could also try to store the values of everything in trip_cost() into a variable and return the variable as sometimes that works. Otherwise I am stumped to.

#7

i found the culprit. i think its something to do with the code convention.

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

i shouldn't place the "+ plane_ride_cost(city)" on the next line.

Thanks