3. Getting There Please Help


#1



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


Error message that says "Oops try again! Did you create a function called plane_ride_cost()?"
My functions also in red either on my console like in the example. Does that even matter?
*In Dr. Evil voice "What does it all mean bazzle?"


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 can't have a condition since its everything else


#3

Color highlighting is good for singling out keywords, numbers, strings and other expressions, and also for indicating syntax errors. Other than that, it has no meaning, per se. Just easier to read.

The issue in the above code is the last branch. It too should be an elif so it does not default to Los Angeles. When no city is found it will return None which is what the SCT expects.


#4

SWEET BABY JESUS!! Thanks bro why is it something that simple? So lets see if I'm understanding this correctly now if the last else statement has a condition it should be changed to elif so that way it doesnt skip straight to the end and send an error message?


#5

It should be an elif condition so that Los Angeles is only returned if it actually is the city value. An else is not a condition, but a default action in the event none of the cases is met. We don't want or need a default for this function. Python will return None, which is what we do want. The no return default.


#6

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