Need help on a projet plss


#1

Exercice link

Hello Everyone,
I have been trying to make this code work, I’ve watched couples times the video, trying to find with the error is but the code still doesn’t work. Really need your help !

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.4))

shipping_premium = 125.00

print (shipping_premium)

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 = 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"
    cost = premium
  else:
    method = "drone"
    cost = drone
  
  print(
  "The cheapest option available is $%.2f with the %s shipping."
  % (cost, method)
  )

Many thanks !!


#2

Hello :slight_smile:

Ok, so execution of this script results in this error message:

  line 46
    cost = ground
                ^
IndentationError: unindent does not match any outer indentation level

This tells us a lot. Python uses indentation to mark the blocks of code, so this is a really important part of your code. Let’s take a closer look at this part:

This is how my editor renders your code, do you see the gray marks (dots and arrows) to the left of each line of code? This feature is called “whitespace rendering”, every dot is a space, every arrow is a tab. My editor renders tab as a double space, but this is just a matter of settings, it could render tab even as eight spaces. And this is problematic for Python, it does not really know how to treat tabs mixed with spaces.

To solve the error you have to replace these two tabs with double spaces.

To not make the same mistake again you might want to think about using an external editor to write the code (this will allow you to render the whitespace in the editor, it’s really helpfull in Python programming) and use Codecademy editor only as a place to execute the code.


#3

Hello !
Okay thank you so much, that was very helpful. :slight_smile:


#4

You’re very welcome :panda_face: