# Sal's Shipping Help Please

Hello,

I am following along on Sal’s shipping exercise here. This is the code as follows but it doesn’t quite make sense when I change the number on my weight value and its above 10 it only stops at the 2nd elif statement and prints 95 if for example the weight is 25. Basically any number that should be out of that 2nd elif statements range still only prints the number in reference to that elif statement. Why?

Thank you.

# Ground Shipping

weight = 25

if weight <= 25:

cost_ground = weight * 1.5 + 20

elif weight > 2 or weight <= 6:

cost_ground = weight * 3.00 + 20

elif weight > 6 or weight <= 10:

cost_ground = weight * 4 + 20

else:

cost_ground = weight * 4.75 + 20

print (cost_ground)

#prints 95

whoops this is the correct weight value

# Ground Shipping

weight = 25

if weight <= 2:

cost_ground = weight * 1.5 + 20

elif weight > 2 or weight <= 6:

cost_ground = weight * 3.00 + 20

elif weight > 6 or weight <= 10:

cost_ground = weight * 4 + 20

else:

cost_ground = weight * 4.75 + 20

print (cost_ground)

Have a close look at the comparisons you’re making use of, e.g. `elif weight > 2 or weight <= 6`.

If you’re uncertain try a few simple statements with print or similar just to confirm whether or not it’s behaving the way you expect.

So I changed some things around here

# Ground Shipping

weight = 150

if weight < 2:

cost_ground = weight * 1.5 + 20

elif weight == 2 or weight < 6:

cost_ground = weight * 3.00 + 20

elif weight == 6 or weight < 10:

cost_ground = weight * 4 + 20

else:

cost_ground = weight * 4.75 + 20

print (cost_ground)

This now outputs the correct numbers I am looking for.

The problem is that these are the parameters that needed to be set and I was trying to word them literally.

Weight of Package Price per Pound Flat Charge
2 lb or less \$1.50 \$20.00
Over 2 lb but less than or equal to 6 lb \$3.00 \$20.00
Over 6 lb but less than or equal to 10 lb \$4.00 \$20.00
Over 10 lb \$4.75 \$20.00

Omg I figured it out… I needed to use the and operator and not the or operator to make it work in the proper way… Haha.

1 Like

4 posts were split to a new topic: Cannot seem to find the error