4. Transportation


#1



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


Oops, try again. Your code looks a bit off. Feel free to peek back at earlier exercises if you need a refresher! Your code threw the following error: unindent does not match any outer indentation level (python, line 7). It looks like the error is in a previous exercise, and I'm pretty certain the code is right.


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:
        cost - 50
    elif days >= 3 and days <= 6:
        cost - 20
    else:
        return cost


#2

Check your indentation (which is what your syntax error also says)


#3

I'm 100% sure I don't have errors on the code. It says "Your code threw the following error: unindent does not match any outer indentation level (python, line 7). Line 7 is:

elif city == "Tampa":

There is no syntax error on it


#4

Maybe it's just a typing error, but I'm getting mad at this


#5

you have to make sure elif is lined up with if like this:

if city == ("Charlotte"):
return 183

elif city == "Tampa":
    return 220

elif city == ("Pittsburgh"):
    return 222

elif city == ("Los Angeles"):
    return 475

#6

It still gives me error messages.


#7

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:
cost -= 50
elif days >= 3 and days <= 6:
cost -= 20
else:
return cost

print rental_car_cost(4)

Oops, try again. It looks like rental_car_cost returns None instead of the correct amount (100) for 3 days.


#8

Now it's lined up as you said


#9

You definetly need the indentation like you had in your first post (4 spaces in). I struggeled with the "3 days not showing adding to 100" thing.

Then I realized I need to "finish each check" by reutning the cost for each check. So I simply added return cost under each "statemnt check" for lack of a better deacription.

Like so:

if days >= 7:
cost -= 50
return cost
elif days >= 3:
cost -= 20
return cost
else:
return cost


#10

I'm sorry for not spell checking.


#11

Thanks a lot man!!!!!


#12

I was at about 2 weeks struggling with this. Does this annoying thing called 'indentation' also exist in another languages or just in Python? Mind I already know HTML, CSS, Javascript and PHP and I've never had such error...


#13

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

this worked for me try this


#14

return cost -50
return cost -20

worked for me


#15

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