Code works but reports this error: try again. trip_cost('Tampa', 0) returned 780.0 instead of the correct value 220


could anyone give me a hint about why I get errors like: Oops, try again. trip_cost('Tampa', 0) returned 780.0 instead of the correct value 220

The code works whatever I enter but I always get an error about a city that has not been entered and an incorrect amount for it.

city = raw_input("What city are you visiting.")
nights = float(raw_input("How many nights will you be staying for?"))
days = float(raw_input("How many days will you be renting a car?"))

def hotel_cost(nights):
return 140 * nights
print "the price per night"
print hotel_cost(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
    print "Please, choose a city from our list."

def rental_car_cost(days):
cost = 40 * days
if days >= 7:
return cost - 50
elif days >=3:
return cost - 20
return cost

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

print"Rental car costs:"
print rental_car_cost(days)
print "Overall cost: "
print rental_car_cost(days) + plane_ride_cost(city) + hotel_cost(nights)


How to go about figuring it out yourself:

Reproduce the incorrect result by calling your function the way that the Codecademy error message mentions.

Add print statements in your code which explain what it is doing step by step.

Compare what is printed with what you expect.


Thank you ionatan, I fugured it out after a long trial and error run.


I keep getting those messages as well, if i input Los Angeles, for example, i get a Pittsburgh,0 should have been X number instead of Y number.