Sal's Shipping Only Printing the Premium Shipping Method

The weights which have the premium shipping as the cheapest shipping are the only weights which print the print statement. Otherwise, the program is not printing.

Please see this topic:

How to ask good questions (and get good answers)

without crucial information (like the code), its really difficult to tell what might be causing this problem

def ground_shipping(weight):
if weight < 2:
return weight1.5 + 20
elif weight <= 6:
return weight
3 + 20
elif weight <= 10:
return weight4 + 20
else:
return weight
4.75 + 20
print(ground_shipping(8.4))
premium_ground_shipping = 125
def drone_shipping(weight):
if weight < 2:
return weight4.5
elif weight <= 6:
return weight
9
elif weight <= 10:
return weight12
else:
return weight
14.25
print(drone_shipping(1.5))
def cheapest_shipping(weight):
ground = ground_shipping(weight)
drone = drone_shipping(weight)
premium = premium_ground_shipping
if ground < premium and ground < drone:
method = “standard ground”
cost = ground
elif drone < premium and drone < ground:
method = “drone”
cost = drone
else:
method = “premium ground”
cost = premium
print(
“The cheapest shipping method is $%.2f with %s shipping method”
% (cost, method)
)
cheapest_shipping(4.8)
cheapest_shipping(41.5)

One possible problem that could be surmised is that the print statement is confined to the else branch. That being the case, one would need to reduce the indentation so the statement follows all the if clauses.

That was the problem. Thanks!!!

1 Like

its really helpful to understand stuff

1 Like