Getting There - with Dictionary


#1


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

It looks like plane_ride_cost does not return 183 when the city is Charlotte.

i understand what the correct said(using if elif else), but how to use "dictionary" instead?

thanks in advance!


def hotel_cost(nights):
    cost = nights * 140
    return cost
    
def plane_ride_cost(city):
    city = {"Charlotte": 183, "Tampa": 220, "Pittsburgh": 222, "Los Angeles": 475}
    return city


#2

Hi @amberson,

The function parameter specified here is city ...

def plane_ride_cost(city):

However, in the next line you are overwriting that parameter with the dictionary.

Use a new variable instead to represent the dictionary. Then use city as a key to access the dictionary via that new variable.


#3

thanks a lot!
i input these code instead and it works!! :slight_smile:

def hotel_cost(nights):
cost = nights * 140
return cost

def plane_ride_cost(city):
choices = {"Charlotte": 183, "Tampa": 220, "Pittsburgh": 222, "Los Angeles": 475}
return choices[city]


#4