Hi I am trying to do the exercise “Sal’s Shipping”. I watched the video too and already searched for the UnboundLocalError: message but I still dont understand it and have no idea why I am getting this error message. Can someone help me please?
Below is my code.
def costs_ground_shipping(weight): if weight <= 2: prie_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(costs_ground_shipping(8.4)) premium_ground_shipping = 125.0 def drone_shipping(weight): if weight <=2: prie_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 price_per_pound * weight print(drone_shipping(1.5))
And this is the error message:
Traceback (most recent call last):
File “script.py”, line 25, in
File “script.py”, line 24, in drone_shipping
return price_per_pound * weight
UnboundLocalError: local variable ‘price_per_pound’ referenced before assignment