mercredi 16 octobre 2019

How to increment something multiple times?

So I have this body of code:

 def effective_rate(db : {str: {(int,int) : float}}, state : str, income : int ) -> float:
        tax = 0
        for state in db.values():
            for(lower_limit, higher_limit), tax_rate in state.items():
                if (income >= lower_limit):
                    tax = tax + (tax_rate*(higher_limit - lower_limit))
                    if (income <= higher_limit):
                        tax = tax + (tax_rate*(income-lower_limit)) 
                        return tax

and this is to check my code:

db1 = {'CT': {(      0,  12_499): .02,
                      ( 12_500,  49_999): .04, 
                      ( 50_000,    None): .06},

               'IN': {(0, None): .04},

               'LA': {(      0,   9_999): .03,
                      ( 10_000,  12_499): .05,
                      ( 12_500,  49_999): .055,
                      ( 50_000, 299_999): .06,
                      (300_000,    None): .078},

                'MA': {(0, None): .055}}
        answer = effective_rate(db1,'CT',40_000)

The issues I run into is that my result should print 0.0337495 another issue is that if a higher_limit is None, it raises a TypeError: unsupported operand type(s) for -: 'NoneType' and 'int' How would I make it that it increments more than just once for the if statement and correctly? And how to stop the error from raising?

Aucun commentaire:

Enregistrer un commentaire