Please help as i am missing something


#1



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):
    rent= 40*days
    if days>=7:
        rent -=50
    elif days>=3:
        rent -=20
    return rent

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

    

Error-- Traceback (most recent call last):
  File "python", line 27, in <module>
  File "python", line 26, in trip_cost
NameError: global name 'nights' is not defined


#2

You are attempting to use nights as an argument for the function, but it is not defined in the program. You should be using the number of days you will be in the hotel.


#3

Thank you,

but now its giving error-
Oops, try again. trip_cost('Tampa', 3) returned 1970 instead of the correct value 740

this is the modified code -----

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):
rent= 40*days
if days>=7:
rent -=50
elif days>=3:
rent -=20
return rent

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


#4

return rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city)

#5

does it really work as I have tried many and do not want to waste my time changing it again when it may be wrong


#6

That is the exact return statement I used to complete the exercise. If it does not work, there is something else wrong with the code that I overlooked.


#7

It helped,
Thank You.


#8

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