IndentationError: unindent does not match any outer indentation level

def shipping_cost_ground(weight): if weight <= 2: price_per_pound = 1.50 elif weight <= 6: price_per_pound = 3.00 elif weight <= 10: price_per_pound = 4.00 else: price_per_pound = 4.75 return 20 + (price_per_pound * weight) print(shipping_cost_ground(8.40)) ground_shipping_premium = 125.00 def shipping_cost_drone(weight): if weight <= 2: price_per_pound = 4.50 elif weight <= 6: price_per_pound = 9.00 elif weight <= 10: price_per_pound = 12.00 else: price_per_pound = 14.25 return price_per_pound * weight print(shipping_cost_drone(1.5)) def print_cheapest_shipping_method(weight): ground = shipping_cost_ground(weight) premium = ground_shipping_premium drone = shipping_cost_drone(weight) if ground < premium and ground < drone: method = "standard ground" cost = ground elif premium < ground and premium < drone: method = "premium ground" cost = premium else: method = "drone" cost = drone print( "The cheapest option avaliable is $%.2f with %s shipping." method = "premium ground" cost = premium else: method = "drone" cost = drone print( "The cheapest option avaliable would be $%.2f with %s shipping." % (cost, method) ) print_cheapest_shipping_method(4.8) print_cheapest_shipping_method(41.5)

Python is very strict about indentation.

Generally you might see a variety of 2-space, 3-space and 4-space indents (all explicit) or some people do a 3-space single tab.

Either way, whichever you pick has to be used consistently for python to recognize it.
I recommend the 3 or 4 space ones as you can clearly tell when it’s off or not.

Moreover, text-editors like vs code, sublime, etc. are excellent at catching these and fixing them for you (even converting your whole file into one style or the other).

3 Likes

The error seems to be picked up around line 39.

1 Like