# Why isnt this working?

I’m not sure why my last function is not working? I basically copied what the walk through video did for the last function.

My math is sound on the top 2. I know I’m missing something.

The only time it returns correctly is when the premium is the least expensive.

``````def ground_shipping(weight):
if weight <= 2:
return weight * 1.50 + 20
elif weight <=6:
return weight * 3.00 + 20
elif weight <=10:
return weight * 4.00 + 20
else:
return weight * 4.75 + 20
# Checking my math
print("\$" + str(ground_shipping(10)))

def drone_shipping(weight):
if weight <= 2:
return weight * 4.50
elif weight <=6:
return weight * 9.00
elif weight <=10:
return weight * 12.00
else:
return weight * 14.25
# Checking my math
print("\$" + str(drone_shipping(1.5)))

def best_shipping(weight):

ground = ground_shipping(weight)
drone = drone_shipping(weight)

if ground < drone and ground < premium:
method = "standard ground"
cost = ground

if drone < ground and drone < premium:
method = "drone"
cost = drone

else:
print("The cheapest option available is \$%.2f with %s shipping."
% (cost, method))

best_shipping(10)

``````

You aren’t printing or returning the results for these if statements:

Your function is working, but the output isn’t being printed or returned, so you can’t see it when you call your function.

1 Like

The print() is in the function. That’s supposed to work as the global return? That’s how the walkthrough has it formatted as well.

``````
print("The cheapest option available is \$%.2f with %s shipping."
% (cost, method))

``````

Your print statement is indented underneath the `else:`, that means your print statement is only accessed when the else block is run. Un-indent your print statement and see if it works.

2 Likes

Ohhhh boy…

I knew it would be something so simple and I was driving myself crazy haha.

Thank you!!

1 Like