Transportation


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/learn-python/lessons/taking-a-vacation/exercises/transportation-?action=lesson_resume&link_content_target=interstitial_lesson

<In what way does your code behave incorrectly? Include ALL error messages.>
no matter how many times i re-write my code, it keeps coming out wrong. I’ve done it so many times i’ve memorized it. i know it’s correct. i know it’s the ■■■■ indentation.
I wanna know why it keeps happening what am i missing, as far as i know not a ■■■■ thing, not a colon out of place. so why when i press enter instead of going to the far left to start the elif is under the if statement. as if im adding on. when moving everything in place manually its still incorrect…

<What do you expect to happen instead?>

```python

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

that’s my code.
when pressing “Get Code”

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

<do not remove the three backticks above>

#2

look:

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

print rental_car_cost(9)
print rental_car_cost(2)
print rental_car_cost(5)

if the car is rented for 9 or 2 days, the function outputs None while it should output the cost, for renting the car 5 days, it goes well. This is because the indent of return cost is wrong, the return statement is currently only reached in the elif clause, but the cost should always be returned


#3

Sorry for the late reply tried to reply back long ago but it kept saying insecure page.
To your reply, I already knew it was the indent, cause that’s what i wrote. that wasn’t my question but thank you I really do appreciate your reply.

P.S. the first time I wrote the code the indentation was fine, i passed the lesson. but i tend to do it couple, sometimes a few times so i can understand the syntax more. after resetting it, that’s when the indentation problem suddenly arose, i just shook it off as it might be a small glitch or something.


#4

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