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


#1

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
else:
    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
else:
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)


#2

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.


#3

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


#4

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.

Thanks