8. Taking a Vacation, Pull it together - Nights not defined


#1

Hi, very new to this so please be patient.

I have the error message trip_cost('Charlotte',0) raised an error, global name 'nights' is not defined.

Here is what I have.

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

It will probably be really simple but I'm stumped.


#2

here:

return hotel_cost(nights) + city +rental_car_costs(days)

nights is not defined, the instructions tell you to use days as argument?


#3

Thanks, so I'm having a senior moment so the line should read what exactly?

return hotel_cost + rental_car_costs(days) + city

If I do that I get a new error msg ('Charlotte' 2 raised an error:unsupported operand type(s) for :'function' and int.


#4

inside your trip_cost function, you call other functions:

return hotel_cost(argument) + plane_ride_cost(argument) + rental_car_cost(argument)

see how i call the function you build earlier? Now you fill in the arguments


#5

Many thanks stetim94,. Typed that in and it doesn't like the place names for some reason.


#6

That's exactly how I have now typed it with the relevant arguments and still the error messages occur with the place names, Tampa, Pittsburgh etc,.

I haven't changed it from the previous exercise so I'm completely puzzled.

Weird.


#7

did you check with the instructions that city should be the argument for plane_ride_cost? If you need more help, post an updated version of your code


#8

tks, here is what I have as the finished code which throws the errors up,

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

I really appreciate the help, getting very confused.


#10

I've fixed it. Thanks for the help.

I had def rental_car_cost instead of def rental_car_costs.

Doh! and Double Doh!!!

Please close the thread.


#11