Sal's Shipping project help

can anyone tell me what I’m doing wrong here? It’s not returning an error message, but it’s not printing anything either. It will however only print any “weight” over 10.

weight = 8.4

#Ground Shipping

if weight <= 2:
cost_ground = weight * 1.5 + 20
elif weight <= 6:
cost_ground = weight * 3 + 20
elif weight <= 10:
cost_ground = weight * 4 + 20
else:
cost_ground = weight * 4.75 + 20
print(“Ground Shipping $”, + cost_ground)
premium_ground = 125.00

Hi,
Your code hasn’t formatted correctly, but I’m thinking it looks like this;
(incidently, using the < / > option to paste your code into makes it easier to read)

weight = 8.4

#Ground Shipping

if weight <= 2:
    cost_ground = weight * 1.5 + 20
elif weight <= 6:
    cost_ground = weight * 3 + 20
elif weight <= 10:
    cost_ground = weight * 4 + 20
else:
    cost_ground = weight * 4.75 + 20
    print(“Ground Shipping $”, + cost_ground)
premium_ground = 125.00

That it prints when ‘weight’ is over 10 suggests it’s only running that line when it’s associated with the ‘else’ block of code.

The line with print on shouldn’t be indented.

Hope that helps

2 Likes

That fixed it, thank you!

1 Like