Putting it together


#1



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


not sure if i have errors in previous exercises or if it has a bug. i got this far with 'Tampa' spelt like 'Tempa'.
i put Tampa in the print line because thats what city i got in the previous exercises.


def hotel_cost(nights):
    return (nights) * 140
def plane_ride_cost(city):
    if city == "Charlotte":
        return 183
    elif city == "Tempa":
        return 220
    elif city == "Pittsbourgh":
        return 222
    elif city == "Los Angeles":
        return 475
    else: 
        return plane_ride_cost(cost)    
def rental_car_cost(days):
    cost =  40 * days
    if days >= 7:
        cost -= 50
    elif days >= 3 and days <= 6:
        cost -= 20
    return cost

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

Oops, try again. plane_ride_cost('Tampa') raised an error: global name 'cost' is not defined

so i changed it to this......

def hotel_cost(nights):
    return 140 * nights
def plane_ride_cost(city):
    if city == "Charlotte":
        return 183
    elif city == "Tampa":
        return 220
    elif city == "Pittsbourgh":
        return 222
    elif city == "Los Angeles":
        return 475
  
def rental_car_cost(days):
    cost =  40 * days
    if days >= 7:
        cost -= 50
    elif days >= 3 and days <= 6:
        cost -= 20
    return cost

def trip_cost(city, days):
    return hotel_cost(nights) + plane_ride_cost(city) + rental_car_cost(days)
    print trip_cost(5, 'Tampa', 5)
Oops, try again. plane_ride_cost('Pittsburgh') returned None instead of the correct value 222


#2

Hi, @jhcroydon,

You still have this in the plane_ride_cost function ...

elif city == "Pittsbourgh":

That needs to be corrected.

Also consider whether this, within the trip_cost function, will work ...

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

#3

i already changed 'Tampa' in the second code i done . I also changed the return to... return rental_car_cost(days) + hotel_cost(days)+ plane_ride_cost(city) ....... still coming up with.... Oops, try again. plane_ride_cost('Pittsburgh') returned None instead of the correct value 222


#4

Change "Pittsbourgh" to "Pittsburgh" in the plane_ride_cost function.


#5

genius!!! Thank you. I have such bad spelling!!


#6