#" Ground Shipping "
if weight <= 2:
cost_ground = weight * 1.5 + 20
elif weight > 2 or weight <= 6:
cost_ground = weight * 3.0 + 20
elif weight > 6 or weight < 10:
cost_ground = weight * 4.0 + 20
elif weight > 10:
cost_ground = weight * 4.75 + 20.0
print (cost_ground)
Here is my problem the first 2 print out the correct price but when i try the 8.4 pounds in the example it returns 45.2 instead of 53.6 that it should be and the 4th elif statement does not print the right amount also
The problem is that you are falling into the first elif. You are comparing if the weight is greater than 2 OR less than or equal to 6. Since you are using OR, if either condition is true, the whole condition is true. Since 8.4 is actually greater than 2, the whole condition is true, and it takes 8.4 * 3 and adds 20 to get 45.2. To make it work, you would need to use AND instead of OR.
All that said, though, you don’t need to check if weight is greater than 2 at all, since the first condition of the if statement already ensures that. You will only get to the first elif if the weight is greater than 2. So, your if statement could be simplified as the following. Also, the last elif could simply be an else, since by definition, you couldn’t get to this point unless the weight was greater than 10. (Note: the exercise does say “weight greater than 6 and less than or equal to 10.” That is also corrected below.)
Net, each of the elif sections only need to compare the next level, since you can’t get to that elif unless you already were greater than the earlier compares.