What does this mean?


#1


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

File "python", line 18
SyntaxError: 'return' outside function

I don't know the logic of the function looks sound to me but its clearly not doing what I think it should nor is it written the way the computer wants to read it.


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


#2

Well first off, if that is your whole code for this part of the lesson, you are missing some things! No i dont mean like def plane_ride_cost and such but you are missing more stuff under your rental_car_cost. Go back and take a look at the instructions and include everything in it then we can start looking at errors! :smiley:


#3

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


#4

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

return cost

I looked up indention rules and modified the code but I keep getting the same syntax error message

File "python", line 22
SyntaxError: 'return' outside function


#5

Ok so it would seem your code is completely correct just don't have the right indention or at least from what I can see. You should have an indention set like this:

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

#6

Once again thank you. Played around with indention and will never forget to indent 4 spaces to the right ever again!


#7

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