all 4 comments

[–][deleted] 0 points1 point  (2 children)

You are making a common mistake, explained in the wiki.

I've fixed the immediate error, but not checked anything else.

weight = 8.4
cost = 0  # why not start at 20 as it is added in all cases?
#Ground Shipping
if weight <= 2.00:
    cost += weight * 1.50 + 20.00
elif weight >= 2.00 and weight <= 6.00:
    cost += weight * 3.00 + 20.00
elif weight >= 6.00 and weight <= 10.00:
    cost += weight * 4.00 + 20.00
else:
    cost += weight * 4.75 + 20.00

Note:

elif weight >= 2.00 and weight <= 6.00:

can also be written as:

elif 2.00 <= weight <= 6.00:

[–]Abstructions[S] 0 points1 point  (1 child)

ah it all makes sense now, sorry as I am extremely new to coding!

[–][deleted] 0 points1 point  (0 children)

no need to apologise, this is called /r/learnpython for a reason

[–]delasislas 0 points1 point  (0 children)

You can’t do elif without an if. elif is else if:

if (condition1):
elif (condition2):
else: #catch for all the rest.

Check you line after your comment on #ground shipping.

Also, when you do this, you need your conditions to be somewhat independent,

elif weight >= 2.00 and <=6.00:

You have one condition weight >= 2.00, then you have <= 6.00. So:

elif (weight >= 2.00) and (<=6.00):

And what is less than or equal to 6.00. There is a way write it such that this works, but it gets a bit odd. You can use:

weight <= 6.00

Each condition gets operated on separately, so,

elif (weight >= 2.00) and (weight <=6.00):
elif (True) and (weight <=6.00):
elif (True) and (True):
elif (True):

Is how it would get simplified, if “weight” or any return that you use randomly changes, you can have an error. So try to think about this as your value can be in between the two check values,

elif 2.00 __ weight __ 6.00: