Error on number 5


#1



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


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


It to work


def hotel_cost (nights):
    return 140 * nights
def plane_ride_cost (city):
    if "Charlotte" == city:
        return 183
    elif 'Tampa' == city:
        return 220
    elif 'Pittsburgh' == city:
        return 222
    else:
        return 475
def rental_car_cost (days):
    if days >= 7:
        return days * 40 -50
    elif days >= 3:
        return days * 40 -20
    else:
        return days * 40
print hotel_cost(days) + rental_car_cost(nights)  + plane_ride_cost(city)


#2

Here:

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

As it is now, if days meets the condition in the first if statement, it also meets the condition for the elif statement. This means that both lines of code will run.

To fix this, simply add a second condition to your elif statement. Something like and days < 7 would suffice.


#3

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