Transportation: Taking a Vacation


Syntaxerror 'return' outside function line 21

Please tell me what is wrong here

Replace this line with your 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
    elif city == 'Los Angeles':
        return 475
        return 'Price Unknown'

def rental_car_cost(days):
        cost = days * 40
if days >= 7:
        cost -= 50
elif days >= 3:
    cost -= 20
return cost


What is wrong is how the rental_car_cost(days) function has been indented. The way you have done that one, Python thinks that everything from the if days ... line on down is outside the function. This means your program is not going to give you the results that you expect and that Python is going to complain about having a return statement outside of a function.

Take your time and indent so that everything that should be inside the function is. Your first two functions are done correctly.


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