Python 3: Sal's shipping project

thanks tgrtim that’s was helpful

def cheapest(weight):
ground = ground_shipping(weight)
drone = drone_shipping(weight)
premium = 125.00

if ground < drone and ground < premium:
method = “ground”
cost = ground
elif drone < ground and drone < premium:
method = “drone”
cost = drone
else:
method = “any method”
cost = premium

print(“Chepeast method of shipping is %s. Total cost would be %.2f”
% (method, cost))

cheapest(41.5)

I am able to get the answer for 4.8 pounds. But when I try to use 41.5, the error I receive is:

Traceback (most recent call last):
File “script.py”, line 42, in
cheapest(41.5)
File “script.py”, line 28, in cheapest
if ground < drone and ground < premium:
TypeError: ‘<’ not supported between instances of ‘float’ and ‘NoneType’

What am I missing?

one of these variable:

if ground < drone and ground < premium:

seem to be None. Comparing None with float doesn’t go really well (like the error says), so you could print the variable:

print(ground, drone, premium)

to see which is None. Very likely, your ground or drone shipping function doesn’t return anything (None -> the absence of a return value) so you would need to figure out why that is

Hi,

In a way it was. I completed Python 2 first before starting Python 3. Then I just used my knowledge of functions to complete the project. It made it a lot easier. Here is my solution to it, which I think is easier to comprehend:

Ground Shipping

weight = 80
ground_shipping_premium = 125
def ground_shipping(weight):
flat_cost_gs = 20
if weight <= 2:
cost = flat_cost_gs + (2 * weight)
elif weight <= 6:
cost = flat_cost_gs + (3 * weight)
elif weight <= 10:
cost = flat_cost_gs + (4 * weight)
else:
cost = flat_cost_gs + (4.75 * weight)
return cost

print(ground_shipping(8.4))
print(ground_shipping_premium)

Drone Shipping

weight_d = 80
def drone_shipping(weight_d):
cost = 0
if weight_d <= 2:
cost = 4.5 * weight_d
elif weight_d <= 6:
cost = 9 * weight_d
elif weight_d <= 10:
cost = 12 * weight_d
else:
cost = 14.25 * weight_d
return cost

print(drone_shipping(1.5))