5. Pull it Together (please respond asap, super confused right now)


#1



5. Pull it Together

Oops, try again. Your code looks a bit off. Feel free to peek back at earlier exercises if you need a refresher! Take a look at the console window for the error message from the interpreter.
File "python", line 7
SyntaxError: 'return' outside function

I need it to tell me I did it right and move on lol.. when i get stuck like this i lose modivation to learn, but i want to learn

def hotelcost(nights):
    return 140*nights
def planeridecost(city):
    if city == "Charlotte":
        return 183
if city == "Tampa":
    return 220
if city == "Pittsburgh":
    return 222
if city == "Los Angeles":
    return 475
def rentalcarcost(days):
    cost = days *40
if days >= 7:
    cost=cost - 50
    return cost
elif days >=3:
    cost = cost - 20
    return cost 
else:
    return cost;
def tripcost(city, days):

    return hotel_cost(days)+plane_ride_cost(city)+rental_car_cost(days)


#2

All of the above lines are outside of their function block. Add four spaces to each line.


#3

def hotelcost(nights):
return 140*nights
def planeridecost(city):
if city == "Charlotte":
return 183
if city == "Tampa":
return 220
if city == "Pittsburgh":
return 222
if city == "Los Angeles":
return 475
def rentalcarcost(days):
cost = days *40
if days >= 7:
cost = cost -50
return cost
elif days >=3:
cost = cost - 20
return cost
else:
return cost;
def tripcost(city, days):

return hotel_cost(days)+plane_ride_cost(city)+rental_car_cost(days)

alright i fixed the if statements, but now it says line 15 syntax error


#4

def hotelcost(nights):
    return 140*nights
def planeridecost(city):
    if city == "Charlotte":
        return 183
    if city == "Tampa":
        return 220
    if city == "Pittsburgh":
        return 222
    if city == "Los Angeles":
        return 475
def rentalcarcost(days):
    cost = days *40
    if days >= 7:
        cost = cost - 50
    return cost
elif days >= 3:
        cost = cost - 20
    return cost 
else:
    return cost;
def tripcost(city, days):

    return hotel_cost(days)+plane_ride_cost(city)+rental_car_cost(days)

now i got that fixed, but how do i get it to stop saying line 17 syntax error


#5

Check the function names. They are all missing the _ in their names.


#6

but it still says line 17 has the syntax error... no matter what i change


#7

elif days >= 3:
        cost = cost - 20
    return cost 
else:
    return cost;

These are outside of the function.


#8

what does that mean? how do i fix it?


#9

Indent those lines so the in the function code block. Be sure the first return is inside the if block.


#10

def hotel_cost(nights):
    return 140*nights
def plane_ride_cost(city):
    if city == "Charlotte":
        return 183
    if city == "Tampa":
        return 220
    if city == "Pittsburgh":
        return 222
    if city == "Los Angeles":
        return 475
def rental_car_cost(days):
    cost = days *40
    if days >= 7:
        cost = cost - 50
    return cost
    elif days >= 3:
        cost = cost - 20
    return cost 
    else:
    return cost;
def trip_cost(city, days):

    return hotel_cost(days)+plane_ride_cost(city)+rental_car_cost(days)

okay i did that, but it still says line 17 invalid syntax


#11

Add four more spaces of indent to all three return statements.


#12

IT WORKED!!! THANK YOU SO MUCH!


#13

You're very welcome. Indentation is critical in Python. It is how the blocks are defined.


#14