Rental car portion


#1



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


returning error in final execution as in returning 270 instead of 230


I expected the code to execute fully without any problems


def rental_car_cost(days):
    # rental cost per day at $40/days
        cost = days * 40
if days < 3:
 return cost
if days >= 3 and days <= 7:
        cost = days * 40 - 20
   return cost
if days >= 7:
        cost = days * 40 - 50
 return cost
else:
 return cost


#2

The logic is a bit complicated. Perhaps working from highest to lowest will help simplify it.

cost = days * 40
if days >= 7:
    cost -= 40
elif days >= 3:
    cost -= 20
return cost

#3

still having issues with the code as corrected am kinda confused as either print cost @ end of the code or return cost generates an error. Thanks for you help in advance

def rental_car_cost(days):
    # rental cost per day at $40/days
        cost = days * 40
  if days >= 7:
     cost -= 50
  elif days >= 3:
     cost -= 20
     return cost

see error msg:

File "python", line 20
    if days >= 7:
                ^
IndentationError: unindent does not match any outer indentation level

#4

Give the cost line a fresh indent of four spaces.

The return line should not be indented that much.


#5

Thanks for your gracious and prompt response, i still getting the same error. I just encourage that good man like you there to help. Struggling with the indentation for return cost..... last line

thanks again

def rental_car_cost(days): # rental cost per day at $40/days
    cost = days * 40
if days >= 7:
     cost -= 50
elif days >= 3:
     cost -= 20
  return cost

same error:

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


#6

It might be a good idea to rebuild all the indents. Four spaces for the outer lines, eight for the inner. The return line should only have four. For extra measure, remove the comment.


#7

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