Sal's shipping help with code returning correct solution and a second output 'none'

Hi,

Sorry if this isn’t the correct format for a query, I have never posted here before. I have been trying to complete the project Sal’s shipping under the python control flow lessons (https://www.codecademy.com/paths/data-science/tracks/dspath-functions-and-logic/modules/dspath-control-flow/projects/sals-shipping). Basically I have completed the exercise and everything seemed to be working well. However for the last tasks (6 & 7) where you write a function to state the cheapest shipping method, the correct output is returned, but alongside another output “None” I’m not sure why and the guided walkthrough is so different from my solution that I cannot work out where the problem is in my code! I have enclosed the code for the full task below:

``````def ground_shipping_cost(weight):
if weight <= 2:
cost = 1.5 * weight + 20
elif weight <= 6:
cost = 3 * weight + 20
elif weight <= 10:
cost = 4 * weight + 20
else:
cost = 4.74 * weight + 20
return cost

print(ground_shipping_cost(8.4))

def drone_shipping_cost(weight):
if weight <= 2:
cost = 4.5 * weight
elif weight <= 6:
cost = 9* weight
elif weight <= 10:
cost = 12 * weight
else:
cost = 14.25 * weight
return cost

print(drone_shipping_cost(1.5))

def price_calculator(weight):
ground = ground_shipping_cost(weight)
drone = drone_shipping_cost(weight)
if ground < drone and ground < premium:
cheapest = ground
return print('The cheapest method is premium ground shipping at a cost of \$' + str(cheapest) + '.')
if drone < ground and drone < premium:
cheapest = drone
return print('The cheapest method is premium ground shipping at a cost of \$' + str(cheapest) + '.')
return print('The cheapest method is premium ground shipping at a cost of \$' + str(cheapest) + '.')

print(price_calculator(4.8))
``````

So for example when the print(price_calculator(4.8)) is executed it outputs:
“The cheapest method is premium ground shipping at a cost of \$34.4.
None”

Sorry for the long post, if anyone could tell me why this extra “None” is printed I’d be really grateful, it seems the function does produce the correct value too.

If you call print twice maybe you should expect two things to get printed too? The obvious remedy would be to use print fewer times.

Also, that’s not a correct algorithm for determining the smallest of three, as it requires the value to be smaller than the two others (which isn’t the case if the two smallest values are equal) …and you only need to carry out two comparisons, not six

Thanks for your help and apologies I should have noticed that I had been calling print twice, that was easy to resolve.

In regards to the second part of your answer, would you suggest using elif and else to reduce the number of comparisons? I had considered the case in which two of the values were equal but I wasnt sure how best to address that. Again I had watched the walkthrough and I can’t see that it has been addressed there either, although I could be incorrect.