3. Getting There


#1



What am I doing?


I'm not sure what I'm doing wrong. Every time I submit, it says "It looks like plane_ride_cost does not return 220 when the city is Tampa."

Here is the key:
"Charlotte": 183
"Tampa": 220
"Pittsburgh": 222
"Los Angeles": 475


Replace this line with your code. 

def hotel_cost(nights):
    return 140 * nights

def plane_ride_cost(city):
    if "Charlotte":
        return 183
    if "Tampa":
        return 220
    if "Pittsburgh":
        return 222
    if "Los Angeles":
        return 475


#2

Nevermind, I ended up figuring it out.


#3

There was nothing blatantly wrong with your code. Since every branch is a return, there is no need for elif. However, I suspect that was the case in solving your problem. Was that an expected element in the code?

When you come back to review this module (as I hope you will), try a new tack using a dictionary and an exception, KeyError.

cities = {
    "Charlotte": 183,
    "Tampa": 220,
    "Pittsburgh": 222,
    "Los Angeles": 475
}
return cities[city]

Should prove to be fun.


#4

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