Sal's shipping project - Python Control Flow

Hi, This is my first question on codeacademy, it relates to Python Control Flow in Lesson 6, the last project, Sal’s shipping. I have tried and figure out why my code is returning both the correct answer but also “none”… Not sure what is happening - can anyone help me eliminate the “none”?
Thanks in advance for any help :slight_smile: Much appreciated!!

Please see link below:

# The regular ground shipping cost calculation function
def ground_shipping_cost(weight):
  flat_rate = 20.0
  if weight <= 2.00:
    ground_cost = (flat_rate + (weight * 1.50))
    return ground_cost
  elif weight > 2.00 and weight <= 6.00:
    ground_cost = (flat_rate + (weight * 3.00))
    return ground_cost
  elif weight > 6.00 and weight <= 10.00:
    ground_cost = (flat_rate + (weight * 4.00))
    return ground_cost
  else:
    ground_cost = (flat_rate + (weight * 4.75))
    return ground_cost

premium_cost = 125.00

# The drone shipping cost calculation function
def drone_shipping_cost(weight):
  if weight <= 2.00:
    drone_cost = weight * 4.50
    return drone_cost
  elif weight > 2.00 and weight <= 6.00:
    drone_cost = weight * 9.00
    return drone_cost
  elif weight > 6.00 and weight <= 10.00:
    drone_cost = weight * 12.00
    return drone_cost
  else:
    drone_cost = weight * 14.25
    return drone_cost

# The cheapest shipping method printed to user function 
def print_best_cost_shipping(weight):
  ground = ground_shipping_cost(weight)
  premium = premium_cost
  drone = drone_shipping_cost(weight)
  if ground < premium and ground < drone:
    cost = ground
    method = "standard ground"
  elif premium < ground and premium < drone:
    cost = premium
    method = "premium ground"
  else:
    cost = drone
    method = "drone"
  print(
   "The cheapest option available is $%.2f with %s shipping."
   %(cost, method))

print(print_best_cost_shipping(4.8))  
print(print_best_cost_shipping(41.5))
  

at the bottom of your code, you are calling print_best_cost_shipping() with a print statement. So Python is going to the function, doing whatever it needs to do, and then trying to fulfill that print() you used to call the function in the first place. Your function doesn’t return anything so that print has nothing to print and therefore gives you a none

2 Likes

Ahhh! That’s correct :smiley: Thank you so much :slight_smile:

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.