Sals Shipping: receiving 'none'

https://www.codecademy.com/paths/build-chatbots-with-python/tracks/introduction-to-python-and-chatbots/modules/learn-python3-control-flow/projects/sals-shipping
Can’t figure out where the bug is, maybe you’ll see it?
script.py

def shipping_ground(weight):
  flat_charge = 20.00
  if weight <= 2:
    price_per_pound = 1.50
  elif weight > 2 and weight <= 6: 
    price_per_pound = 3.00
  elif weight > 6 and weight <= 10:
    price_per_pound = 4.00
  else:
    price_per_pound = 4.75

  cost = price_per_pound*weight +flat_charge
  return cost


print(shipping_ground(8.4))

Also I watched a little of the walk through to see if I could figure it out, however my <= does not turn white like his does… in case that is any sort of indicator.

Hello, @spacedaddy, and welcome to the Codecademy Forums!

The issue may relate to indentation. Since your posted code is not properly formatted, users cannot view its indentation effectively.

See How to ask good questions (and get good answers) for advice on how to format code for posting.

In your code, is this statement correctly indented, or is it indented by too much, making it part of the else block?:

return cost

Not sure what I changed, but the following now works! Will investigate further after this is project is fully complete.

#GROUND
def shipping_ground(weight):
  flat_charge_ground = 20.00
 #2lb
  if weight <= 2:
    cost = (1.50* weight) + flat_charge_ground
 #2-6lb
  elif weight > 2 and weight <= 6:
    cost = (3.00* weight)+ flat_charge_ground
  #6-10lb
  elif weight > 6 and weight <= 10:
    cost = (4.00* weight)+ flat_charge_ground
  #10+lb
  else:
    cost = (4.75* weight)+ flat_charge_ground
  return cost

The indentation is correct in your second post. If you had the indentation of the return statement as follows, making it part of the else block, the function would have returned None under some circumstances, because the return statement would only execute when the else block is executed:

  else:
    cost = (4.75* weight)+ flat_charge_ground
    return cost

When a function terminates without executing a return statement, None is returned.

1 Like