Sal's Shipping Help Python

Hi can anyone please help me with question 2 on the project of Sal’s shipping
Cause I generally don’t know what to do

Code:

weight = 23
# Ground Shipping
if weight <= 23:
  print(cost)

Link to Project: https://www.codecademy.com/courses/learn-python-3/projects/python-sals-shipping

Is this all of your code?

The question asks you to write an if/elif/else statement based on the ground shipping table in the intro. So, you have to write it based on the weights supplied in that table.

Did you check the hint?

if weight <= 2:
  cost_ground = weight * 1.5 + 20
elif weight [SOME INEQUALITY]:

You want it to return a value to the caller, not print()

1 Like

Yes ok I now understand, thank you

Would anyone mind helping me with question 2 again, I know I said that I understand, but I have an error

The link to the lesson is at the top

Code:

weight = 3
#"Ground Shipping"
if weight <= 3:
  cost_ground = weight * 1.5 + 20
elif weight >= 6:
  cost_ground = weight * 3 + 20
elif weight >= 10:
  cost_ground = weight * 4 + 20
else: 
  weight > 10:
  cost_ground = weight * 4.75 + 20

You’re not returning anything and the conditions are a a bit off.

You have to follow the chart weights as it’s listed above. The first if should look like this:

if (weight <= 2.0):
    return flatcharge + (weight * 1.50)

(Note: I have flatcharge defined in the function just above the conditional statements, flatcharge = 20). I think that’s another question following 2)

Think of control flow like, “If this, then this.”

"if the weight is this___then do this, elif the weight is this ___ , then do this, etc. The “do” part in this scenario is the return statement, which is the cost. If the first condition is met, a value will be returned. If it’s not met, then it goes to the elifs, etc.

The else part is a bit off. It should cover everything else if the previous conditions are not met.
You already have it set to, elif weight >= 10:, and then you have else: weight > 10... which is incorrect. The else condition covers every other scenario not already covered by the previous conditions.

Like this:

else:
    return flatcharge + (weight * 4.75)

More on if:

And,