My code is as follows;
def ground_shipping(weight): flat_charge = 20 if (weight <=2.0): return 1.50 * weight + flat_charge elif (weight <= 6.0): return 3.00 * weight + flat_charge elif (weight <= 10.0): return 4.00 * weight + flat_charge else: return 4.75 * weight + flat_charge print(ground_shipping(8.4)) premium_shipping = 125.00 def drone_shipping(weight): if (weight <=2.0): return 4.50 * weight elif (weight <= 6.0): return 9.00 * weight elif (weight <= 10.0): return 12.00 * weight else: return 14.25 * weight print(drone_shipping(1.5)) def statement(weight): ground = ground_shipping(weight) drone = drone_shipping(weight) premium = premium_shipping if (ground < drone and ground < premium): shipping = "ground shipping" cost = ground elif (drone < ground and drone < premium): shipping = "drone shipping" cost = drone else: shipping = "premium ground shipping" cost = premium print("The cheapest shipping method is " + str(shipping) + " for " + str(cost)) print(statement(4.8)) print(statement(41.5))
The problem is, when I run the final two prints, the second works since the if statement just skips to the else part. The first part (4.8 weight) won’t work and I can’t figure out why. I know it should return ‘ground’, but it’s just returning ‘none’.