Error in sals shipping project

Hey guys, how you are doing.

im new at learning python, and im kinda stuck with a code i cant fix for myself, i hope you guys can have a look.

i have tried to make the assignement , but it was kinda hard for me, so to know what i was doing wrong i watched the explanation movie to understand where i go wrong.

however, even when i copy the code from the video i still got a unbountlocalerror

this is the github code url :slight_smile:

and this is the code:

def shipping_cost_ground(weight):

if weight <= 2 :
price_per_pound = 1.50
elif weight <= 6 :
price_per_pound = 3
elif weight <= 10 :
price_per_pound : 4
price_per_pound : 4.75

return 20 + (price_per_pound * weight)


and this is the error i get:

Traceback (most recent call last):
File “”, line 14, in
File “”, line 12, in shipping_cost_ground
return 20 + (price_per_pound * weight)
UnboundLocalError: local variable ‘price_per_pound’ referenced before assignment

someone please tell me what im doing wrong.

and this is my first week, please be kind.

thankyou my friends.

greets Danny from the netherlands

In your third elif and your else, you have used a colon : instead of an equals sign = to assign the value to price_per_pound. Hence if the weight falls into these blocks, like it does in your function call, price_per_pound will never be assigned and this will break the program. Changing these two : to = should solve the problem.

1 Like

Agreed with what @adamgaffney96 said, when I was doing this project I didn’t use function since I haven’t learned yet. But this is my code and got accepted into →

NOTE: Please don’t copy, I’m just sharing mine if you need. I have done it in a different way :grinning: .

Codecademy learn-python’s repo

1 Like

sorry man, i feel just like a idiot.

this did the trick, thankyou for helping me man.

greets danny

if im honest, its too diffiult right now, the magic 8 ball was diffiult but ok, but the sal shipping thing let me crap my pants,
often i watch the screen, en have no clue what to do, then i use the hint option to understand, and when i watch the video of matt explaining how to make this assignement i crap my pants again .

this is my first week, i really want to understand, but i think im just stupid.

im glad you guys understand, i hope i understand it too one day.

thankyou for your reply.

greets danny

Everybody moves at their own pace and learns things differently! My very first language I picked up was C++, and I seriously struggled with a lot of concepts in that such as classes and objects. However I persevered, tried out a multitude of languages, and then you find that there’s a lot of similarities between languages and it gives you a lot more practise at developing the problem solving mindset.

The hardest point is getting started, once you get over the initial hump with a concept, just practise, practise, practise and you’ll get there! Don’t be afraid to go back and try lessons you have already completed, sometimes repeating the same one over and over can help you solidify the concept.

Most importantly don’t give up if you’re interested in learning, there’s always a steep curve but it’s incredibly important to keep going and try figure out the best way for you to learn!


Perhaps you’re just going through the lessons too fast. Try to take a step back. That’s my advice. :slightly_smiling_face:

1 Like

Sorry for sending the link to Codecademy’s repo instead of the source code that I have done, but this is the new link @danny1984

Codecademy learn-python’s repo

tnx my friends, its good to hear that smart people like you faces the same struggles as me.

im 37 with a baby girl, and im a carsprayer since i was 14 .
from that age i really interested in computers, and not after a long time i started fixing computers.
it was always my dream to become a programmer, but i was afraid.
now im 37 ,always tired,but im inspired to try this.

thankyou friends.