Topic 3 - Getting there


#1

def hotel_cost(nights):
return 140 * nights

Please help,they say I didn't created a function called plane_ride_cost,but I don't know what's wrong with the code!!

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


#2

Your code:

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

The problem is when you return the price times multiplied by the number of nights, because nights is not a parameter you have set in plane_ride_cost(), so it wont recognise it.


My code:

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:
        return 475

Do you see all of the differences? In mine, there's no return (x) * nights, and there's no elif city == "Los Angeles", because that's been replaced with else .


#3

for the last bit, does it have to be else? It can't be if, elif, elif, elif?

Thanks!

This is my code and I also get the 'did you create a function called plane_ride_cost?' error

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

EDIT: Oh got it! I was missing quotation marks around the cities. The system accepted my elif for the Los Angeles part.


#4

Yes if, elif ... elif does work, but I recommend that you always use if elif else, just for good practice.