"'City' is not defined". Where am I not defining 'city'?


#1



https://www.codecademy.com/courses/python-beginner-P5YtY/1/6?curriculum_id=4f89dab3d788890003000096

Traceback (most recent call last):
File "python", line 29, in
NameError: name 'days' is not defined


I thought that 'city' was defined, and so was expecting my code to work.


def hotel_cost(nights):
    return 140 * nights

def plane_ride_cost (city):
    
    if city == "Charlotte":
        return 183
    if city == "Tampa":
        return 220
    if city == "Pittsburgh":
        return 222
    if city == "Los Angeles":
        return 475
        
def rental_car_cost (days):
    rent = days*40
    if days >= 7:
        rent -= 50
    elif days >= 3 :
        rent -= 20
    else:
        return rent
    
    return rent
    
def trip_cost (city, days, spending_money):
    return hotel_cost(days) + rental_car_cost(days) + plane_ride_cost(city) + (spending_money)
    
print trip_cost ("city", days, spending_money)


#2

Highlight for me where city is defined please.


#3

def plane_ride_cost (city):

if city == "Charlotte":
    return 183
if city == "Tampa":
    return 220
if city == "Pittsburgh":
    return 222
if city == "Los Angeles":
    return 475

Is this it? I think this is it. Do I need to define 'city' again in 'trip_cost'?


#4

Well your error says days is not defined. Not city.

& the instructions say:

After your previous code, print out the trip_cost( to "Los Angeles" for 5 days with an extra 600 dollars of spending money.

and you have:

print trip_cost ("city", days, spending_money).

see anything incorrect here?


#5

Not that I can see. Should I get rid of the quotation marks around city?


#6

Where in your code have you entered the information of which town, amount of days and money that you want to compute the trip cost for? It isn't going to transfer via brainwaves, it needs to be part of the code.


#7

refer to what ionatan said.