Sal's Shipping Exercise returning correct answer + "None."

Hey guys, doing the “Sal’s Shipping” cost comparison exercise, and had a couple questions. I actually wound up doing it twice – I didn’t expand the “Tasks” section so I thought we were just doing it by the seat of our pants, haha. I did it over again after noticing the “Tasks” section and following along with that (I’ll include my original code as well at the end).

My issue is that in addition to returning the expected value (“Your best method would be x at a cost of y”) it’s also returning “None.” on a subsequent line. Here’s my code:

def groundship(weight):
  if weight <= 2.0:
    cost = (weight * 1.50 + 20.00)
  elif weight > 2.0 and weight <= 6.0:
    cost = (weight * 3.00 + 20.00)
  elif weight > 6.0 and weight <= 10.00:
    cost = (weight * 4.00 + 20.00)
  else:
    cost = (weight * 4.75 + 20.00)
  return cost

def droneship(weight):
  if weight <= 2.0:
    cost = (weight * 4.50)
  elif weight > 2.0 and weight <= 6.0:
    cost = (weight * 9.00)
  elif weight > 6.0 and weight <= 10.0:
    cost = (weight * 12.00)
  else:
    cost = weight * 14.25
  return cost

def pricecheck(weight):
  groundcost = groundship(weight)
  dronecost = droneship(weight)
  premship = 125.00
  if dronecost < groundcost and dronecost < premship:
    print("Your cheapest shipping method would be drone shipping, at a cost of $" + str(dronecost) + ".")
  elif groundcost < dronecost and groundcost < premship:
    print("Your cheapest shipping method would be ground shipping, at a cost of $" + str(groundcost)+ ".")
  else:
    print("Your cheapest shipping method would be premium ground shipping, at a cost of $" + str(premship) + ".")

print(pricecheck(41.5))


Can somebody steer me in the right direction? Curious why that “none” pops up. And any suggestions on optimization, alternate methodologies, etc. are welcomed and appreciated. Thanks! Also, here’s my original code if anybody’s curious (in both instances, “None.” appears appended to the result):

def ship_method(weight):
  if weight <= 2:
    groundweight = (weight * 1.50 + 20)
  elif weight > 2 and weight <= 6:
    groundweight = (weight * 3.00 + 20)
  elif weight > 6 and weight <= 10:
    groundweight = (weight * 4.00 + 20)
  elif weight > 10: 
    groundweight = (weight * 4.75 + 20)
  if weight <=2:
    droneweight = (weight * 4.50)
  elif weight > 2 and weight <= 6:
    droneweight = (weight * 9.00)
  elif weight > 6 and weight <= 10:
    droneweight = (weight * 12.00)
  elif weight > 10:
    droneweight = (weight * 14.25)
  if droneweight < groundweight and droneweight < 125.00:
    print("Drone shipping would be your best option and the price would be $" + str(droneweight) + ".")
  elif groundweight < droneweight and droneweight < 125.00:
    print("Ground Shipping would be your best option, and the price would be $" + str(groundweight) + ".")
  else:
    print("Premium ground shipping would be your best option, and the price would be $125.00")

print(ship_method(12))

1 Like

You are trying to print() the result of calling the function pricecheck(41.5), however that function does not return anything so there is nothing to print.

2 Likes

Oh, duh! Thanks so much, couldn’t see the forest for the trees.

3 Likes