Taking a vacation "getting there"


#1



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


what am I doing wrong? it says: File "python", line 11
else city == "Los Angeles":

                                               SyntaxError: invalid syntax (city something wrong with city?)


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
    else city == "Los Angeles":
        return 475


#2

else doesn't require a condition statement like if and elif. It's just simple else: and always just else:. It's ok to end with elif. It doesn't have to always be if....elif....else..... but can also be if....elif...elif.....

So you can have

elif city == "Los Angeles":

instead of just else.


#3

ohh ok, yeah never thought about that, thank you!


#4

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