Taking a Vacation Elif Syntax Error!


#1



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

I cannot find a syntax error here!
File "python", line 17
elif days >= 3:
^
SyntaxError: invalid syntax

This is supposed to be a elif statement. (It has a valid if statement before it)


city_prices = {
            "Charlotte": 183,
            "Pittsburgh": 222,
            "Tampa": 220,
            "Los Angeles": 475
        }

def hotel_cost(nights):
    return 140 * nights

def plane_ride_cost(city):
    return city_prices[city]

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)
    return hotel_cost(days)
    return plane_ride_cost(city)


#2

Oops, forgot to replace the line! Is that a serious problem?


#3

Fixed :slight_smile:

Now coming to your problem, there are two of them.

First, you forgot to put the ) in:

return(days * 40 - 50

Second, this method:

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

is wrong. Only one return statement is executed, if at all, in any function. So, all that your trip_cost method would do is return the rental_car_cost. The hotel and plane ride cost calls would NOT be executed.
You actually have to sum all of them and then return the total.


#4

Ok. Thank you! I now understand.