4/7 Transportation Error

 def rental_car_cost(days):
     return 40 * days
   if days >= 7:
     return days += 50

the error says IndentationError: unindent does not match any outer indentation level for line 3?


Python will ruthlessly enforce its requirement for proper, consistent indentation, because it’s a fundamental part of making sure that code is readable.

Typically, your code will start with no indentation, and then as you add structure such as a for loop or an if-else, the code within those structures gets indented:

def my_function(x):
  if x == 1:
    print "One!"
  elif x == 2:
    print "Lonliest number since the number 1..."
    print "Good choice!"

You can’t have random indentation, as that’s not valid:

def my_function(x):
        print "Function City!"
    if x == 1:
      print "Block 1"

With that in mind, can you see why your code would have an indentation error on line 3?


Nevermind. I fixed the problem


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