Sal's Shipping excercise

I am getting the following error message from line 30 of the code below. Please advise reason for error:

File “script.py”, line 30
if (premium_ground_shipping <= ground_shipping(weight)) and (premium_ground_shipping <= drone_shipping(weight)):
^
IndentationError: unindent does not match any outer indentation level

Code:

def ground_shipping(weight):
if weight > 10:
return (weight * 4.75) + 20
elif weight > 6:
return (weight * 4.00) + 20
elif weight > 2:
return (weight * 3.00) + 20
elif weight > 0:
return (weight * 1.50) + 20
else:
return ’ Please type weight in pounds’

premium_ground_shipping = 125

def drone_shipping(weight):
if weight > 10:
return (weight * 14.25)
elif weight > 6:
return (weight * 12.00)
elif weight > 2:
return (weight * 9.00)
elif weight > 0:
return (weight * 4.50)
else:
return ’ Please type weight in pounds’

def cheapest_shipping_method(weight):
if (ground_shipping(weight) <= premium_ground_shipping) and (ground_shipping(weight) <= drone_shipping(weight)):
return ground_shipping(weight)
if (premium_ground_shipping <= ground_shipping(weight)) and (premium_ground_shipping <= drone_shipping(weight)):
return ground_shipping(premium_ground_shipping)
if (drone_shipping(weight) <= ground_shipping(weight)) and (drone_shipping(weight) <= premium_ground_shipping):
return drone_shipping(weight)

Without seeing how your code is formatted it’s very difficult to say (especially when there’s no indentation), please see the following FAQ: How to ask good questions for details on how to format code for the forums.

You seem to have an indentation error, is there an indent where there shouldn’t be? Make sure your indentation is consistent (the codecademy learning environment chooses two spaces) so always use two spaces for any required indents.

1 Like

This is my first question using the forum, so appreciate your input.

Please ignore my previous question and answer the following question:

  1. How am I am able to print string with a float number in it with 2 decimal points? The following code only prints an integer.

print ‘the cheapest cost is’ + str(int(premium)) + ‘for the premium ground method’

It sounds like you’re looking for some kind of formatting. The following describes a number of methods that can be used to format strings (it covers decimal places and padding)-

1 Like

Thank you. The link is very useful.