Pull it Together


def rental_car_cost(days):
    cost = 40 * days
def hotel_cost(days):
   return 140*days
if days >= 7:
    cost -= 50
elif days >= 3:
    cost -= 20
    return cost
def trip_cost(city, days):
    return city + days
def hotel_cost(days):
    return hotel_cost(days)
def add(city, days):
    return rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city)

If I submit code I am getting following error:
File "python", line 9
SyntaxError: 'return' outside function

Please Help!!!



Looking at line 9:

You are using the return keyword in the wrong place. It should be inside a function or method.
Please also consider formatting your code properly: How do I format code in my posts so we can see your indentation more clearly.


Hey @miniapple8888, I don't think you get an alert so I'm just letting you know that @betarockstar39619 has formatted their code. Now you can continue on with explaining about the "return outside function" error message.



Again, if I look into your code:

It looks like your return at line 9 doesn't belong to a function or method according to the indentation. You might be saying the return at line 9 belongs to the function hotel_cost but it already returned something:

And usually when there is a line like this in a function, every line indented under this line won't be executed. Your code structure looks a bit off. I think the part with the conditionnal statement should go under the rental_car_cost function instead of being left between the hotel_cost and trip_cost functions.


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