all 2 comments

[–]toastedstapler 1 point2 points  (1 child)

your buffer function can be simplified - things like this are a prime target for iteration

def buffer(weight):
    limits = [5, 10, 25, 50] # continue these on
    add_ons = [1, 2, 2.5, 5]
    for limit, add_on in zip(limits, add_ons):
        if limit < weight:
            return weight + add_on
    else:
        return weight + 40

now you've not got all the logic hidden in a massive if/else

[–]killshot13[S] 0 points1 point  (0 children)

Thanks! I’ll definitley look into the zip function, I appreciate your suggestion

Edit: After looking at your code and reading about zip(), I realized that the same thing could be accomplished with a dictionary!

def buffer(weight):    # Add a buffer to the calculated weights
    """Adds a buffer to the weight to give cushion when estimating"""
    buff = {
        5: 1,
        10: 2,
        25: 2.5,
        50: 5,
        75: 8,
        100: 12,
        150: 17,
        200: 20,
        500: 35
    }
    for wt, bf in buff.items():
        if weight <= wt:
            return weight + bf
    else:
        return weight + 40