Taking a Vacation. Transportation


#1



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


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


It is telling me an error That I think is not correct at all. I need help I am sure the line is in the function but it tells me otherwise.

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

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


#2

All of those lines need four additional spaces in the indent.


#3

Thanks for letting me know. I just wanted to be sure what do you mean by additional spaces? I am new to coding and well I am new to some of the lingo.


#4

Python relies upon indentation to determine the scoping and context of code blocks.

Also,

Not needed since the if branch covers 7 or more. This is an elif so the first branch will have been bypassed already for values less than 7. Only values less than 3 will bypass the elif branch.

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

#5

OK thanks for that explanation.


#6

I checked the lesson and my code had the spaces but it had the same problem.


#7

Indentation must be consistent and not ragged. It should not contain mixed spaces and tabs. For best assurance, redo every indent with either four or eight spaces, depending the depth of the block.


#8

ok thanks i will do that.


#9

It gave me the same answer.


#10

Please post your code in a reply. Thanks.


#11

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

#12

Won't get put out right but I do have the return's indented.


#13

But not the function block, itself. cost needs one more space in front, and the if statement needs to indented to line up with that. The returns will be indented further, still. See my example, above.


#14

Thanks it worked and now I can go to next lesson. I


#15

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