I need help, I'm stuck "LINE 54"

def shipping_cost_ground(weight): if weight <= 2: price_per_pound = 1.50 elif weight <= 6: price_per_pound = 3.00 elif weight <= 10: price_per_pound = 4.00 else: price_per_pound = 4.75 return 20 + (price_per_pound * weight) print(shipping_cost_ground(8.4)) shipping_cost_premium = 125.00 def shipping_cost_drone(weight): if weight <= 2: price_per_pound = 4.50 elif weight <= 6: price_per_pound = 9.00 elif weight <= 10: price_per_pound = 12.00 else: price_per_pound = 14.25 return 20 + (price_per_pound * weight) print(shipping_cost_drone(1.5)) def print_cheapest_shopping_method(weight): ground = shipping_cost_ground(weight) premium = shipping_cost_premium drone = shipping_cost_drone(weight) if ground < premium and ground < drones: method = "standard ground" cost = ground elif premium < ground and premium < drones: method = "premium ground" cost = premium else: method = "drone" cost = drone print( "The cheapest option avaliable is $%.2f with %s shipping." % (cost, method) ) print_cheapest_shipping_method(4.8) print_cheapest_shipping_method(41.5)

You’re calling print_cheapest_shipping_method, but you defined the method as print_cheapest_shopping_method.

I noticed that, and I changed it but still the same issue.

Can you post the new code, please?

2 Likes

There’s some spelling mistakes and some indentation stuff that needs to be fixed.

fix spelling line 33 (the function’s name) [mentioned already in a previous post]
fix indent line 33

fix indent lines 35, 36, 37

spelling error line 39 and 42: drones should be drone

1 Like

Were you able to fix the code?
Just remember that indentation matters in Python…especially relevant for functions here and your if, elif, else statements

When de-bugging code it might help to read the code from the bottom —> up. It tells your brain to read the code differently and you might be able to spot errors.

1 Like
def shipping_cost_ground(weight):
    if weight <= 2:
    price_per_pound = 1.50
    elif weight <= 6:
    price_per_pound = 3.00
    elif weight <= 10:
    price_per_pound = 4.00
    else:
        price_per_pound = 4.75
    return 20 + (price_per_pound * weight)
print(shipping_cost_ground(8.4))

shipping_cost_premium = 125.00
def shipping_cost_drone(weight):
    if weight <= 2:
        price_per_pound = 4.50
    elif weight <= 6:
        price_per_pound = 9.00
    elif weight <= 10:
        price_per_pound = 12.00
    else:
        price_per_pound = 14.25
    return 20 + (price_per_pound * weight)
print(shipping_cost_drone(1.5)) 
def print_cheapest_shipping_method(weight):
    ground = shipping_cost_ground(weight)
    premium = shipping_cost_premium
    drone = shipping_cost_drone(weight)
    if ground < premium and ground < drone:
        method = "standard ground"
        cost = ground
    elif premium < ground and premium < drone: 
        method = "premium ground"
        cost = premium  
    else:
        method = "drone"
        cost = drone
    print("The cheapest option avaliable is $%.2f with %s shipping."% (cost, method))
print_cheapest_shipping_method(4.8)
print_cheapest_shipping_method(41.5)
1 Like

Hi,

I saw others already answered. Indeed, indentation pushed your function out of scope. The window was a bit small to see the indentation error at first, but when I copied it into VScode it was quite visible!

Hope this helped a bit.

1 Like
def shipping_cost_ground(weight): if weight <= 2: price_per_pound = 1.50 elif weight <= 6: price_per_pound = 3.00 elif weight <= 10: price_per_pound = 4.00 else: price_per_pound = 4.75 return 20 + (price_per_pound * weight) print(shipping_cost_ground(8.4)) shipping_cost_premium = 125.00 def shipping_cost_drone(weight): if weight <= 2: price_per_pound = 4.50 elif weight <= 6: price_per_pound = 9.00 elif weight <= 10: price_per_pound = 12.00 else: price_per_pound = 14.25 return 20 + (price_per_pound * weight) print(shipping_cost_drone(1.5)) def print_cheapest_shipping_method(weight): ground = shipping_cost_ground(weight) premium = shipping_cost_premium drone = shipping_cost_drone(weight) if ground < premium and ground < drone: method = "standard ground" cost = ground elif premium < ground and premium < drone: method = "premium ground" cost = premium else: method = "drone" cost = drone print( "The cheapest option avaliable is $%.2f with %s shipping." % (cost, method) ) print_cheapest_shipping_method(4.8) print_cheapest_shipping_method(41.5)

Thank you everyone, I was stuck on it for a day, I’ll forsure check indentation, and typos moving forwards! Thanks Again :grinning:

1 Like