Why is code returning an error? Control flow - Sal's Shipping

I don’t understand where I have gone wrong in the Sals Shipping Exercise.
The error returned on my final cheapest_shipping function call is that ground is a nontype, how is this possible.

def ground_shipping(weight):

  if (weight <= 2.0): 

    cost = (weight * 1.5 + 20)

  elif (weight > 2.0) and (weight <= 6.0):

    cost = (weight * 3 + 20)

  elif (weight > 6) and (weight <= 10.0):

    cost = (weight * 4 + 20)

  elif (weight > 10):

    cost = (weight * 4.75 + 20)

  print(cost)

ground_shipping(8.4)

premium_shipping = 125

def drone_shipping(weight):

  if (weight <= 2.0): 

    cost = (weight * 4.5)

  elif (weight > 2.0) and (weight <= 6.0):

    cost = (weight * 9)

  elif (weight > 6) and (weight <= 10.0):

    cost = (weight * 12)

  elif (weight > 10):

    cost = (weight * 14.25)

  print(cost)

drone_shipping(1.5)

def cheapest_shipping(weight):

  ground = ground_shipping(weight)

  drone = drone_shipping(weight)

  premium = premium_shipping

  if ground < premium and ground < drone:

    ship_type = "standard ground"

    price = ground

  elif premium < ground and premium < drone:

    method = "premium ground"

    price = premium

  else:

    method = drone

    price = drone

  print( "The cheapest option available is" + ' ' + method + '. It will cost $' + price)

cheapest_shipping(4.8)

Hi there - welcome to the forums!

printing a value back to the terminal is not the same as returning a value from a function.

If you don’t include a return statement in your functions, Python will return None by default. :slight_smile:

Ah yes, I think i learned a valuable lesson.

I was getting the result i wanted but not able to return a value later.

Thanks!

1 Like