Help with 5-7


#1

I can't figure out what is wrong. It says i need to define the function trip_cost but I have. The code is below.

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

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

#2

You seem to be missing a parenthesis at the end of your function. After plane_ride_cost, you need a parenthesis to close, or you can also just remove the very first one after 'return' as it's unnecessary. Also, you're missing a blank space between the plus sign and plane_ride_cost. I don't know if these throw an error, but it's worth trying, I guess.


#3

I tried that, but it still isn't working.


#4

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:
        return rent - 50
    elif days >= 3:
        return rent - 20
    else:
        return rent

#5

The issue looks to be that you haven't defined

def rental__cost(days):

from what it asks you, you must define a variable first. so...

def rental_car_cost(days):
    rent = 40 * days

Then you can use rent instead of doing

    if days >= 7:
        return (days * 40) - 50

So it would look like this

def rental_car_cost(days):
        rent = 40 * days
        if days >= 7:
            return rent - 50

#6

i tried that code it did not work for me this is what it sed Oops, try again. rental_car_cost(1) returned None instead of the correct value 40 please help me


#7

What is wrong with my code?

def hotel_cost(days):
return days * 140

def plane_ride_cost(city):
if city == "Charlotte":
return 183
if city == "Tampa":
return 220
if city == "Pittsburg":
return 222
if city == "Los Angeles":
return 475
else:
return 'None'

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

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

It says 'Oops, try again. plane_ride_cost('Pittsburgh') returned 'None' instead of the correct value 222'
Don't know what to do. I'm stuck


#8

its a simple spelling mistake, you spelt Pittsburgh wrong, basically missing off the h, change that and you should be fine


#9

here you can find the correct script - it definitely works

def hotel_cost(nights):
return 140*nights
def plane_ride_cost(city):
travel = city.lower()
if travel == 'charlotte':
cost = 183
return cost
elif travel == 'tampa':
cost = 220
return cost
elif travel == 'pittsburgh':
cost = 222
return cost
elif travel == 'los angeles':
cost = 475
return cost
else:
cost = 0
return cost

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

that's all folks


#10

[Codecademy: Taking a Vacation](https://www.codecademy.com/courses/python-beginner-P5YtY/1/4?curriculum_id=4f89dab3d788890003000096)
`


#11

The full Plan your Trip script in the link bellow:

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