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))
premium_ground_shipping = 125.00
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)
premium = premium_ground_shipping
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) + '.')
if premium < ground and premium < drone:
cheapest = premium
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.