Sal's Shipping Project - Variable Confusion

Hi! so i have no previous programming experience but i understand the flow of how the code is supposed to be in order to get to the end result. For the Sal’s Shipping Project it asks to create a variable Weight as well as implies to create a cost and a ground shipping variable. As per the hint, the hint defines a variable ground_cost. My question is, how do you throw in a undefined variable if the variable is not set up at the beginning? For instance, here is my code for this project, and I’ve spent about an hour breaking down each part and going through the flow. This currently only returns the weight because for whatever reason im not catching on to something with this variable ground_cost

weight = 80

cost_ground = 0

#Ground Shipping price

if weight <=2:

cost_ground += weight * 1.5

elif weight <= 6:

cost_ground += weight * 3.00

print(cost_ground + 20)

I think you forgot to write an additional elif or an else (for when the weight is between 6 and 10 and when the weight is more than 10).

weight = 80
cost_ground = 0
#Ground Shipping price

if weight <=2:
  cost_ground += weight * 1.5
elif weight <= 6:
  cost_ground += weight * 3.00
elif weight <= 10:
  cost_ground += weight * 4.00
else:
  cost_ground += weight * 4.75

print(cost_ground + 20)

Next time, please use the </> button and post the code on lines between the ``` and ``` so that your code keeps its formatting in the post.

1 Like

thank you so much for the help! i spent literally 3 hours “theory crafting” why this wouldn’t work. For some reason using += for just one statement wasn’t working but not all of a sudden it works now! and thanks for the future advice on the code this was also my first time posting in the forms and now i know!

The project instructions here need a redo.

Look at the help video posted and it’s nothing like the exercise, he writes functions which so far have not been covered.

I’m also trying to run the code exactly as he typed it and it’s returning a name error saying ‘ground’ isn’t defined.

I found this exercise very confusing.

I saw what you were talking about as I lost my mind trying to figure this out, then when i saw the video and it talked about functions I was like “I didn’t learn this yet”. It was frustrating for the most part but im good now!