income_tax(income) that computes tax using a nested helper function bracket_rate(amount) defined inside income_tax (not at module level). The rate is 0% for amount <= 10000, 10% for the portion above 10000 up to 40000, and 20% for the portion above 40000. income_tax should call the nested helper to compute and return the total tax owed as a float, using simple bracket math (only the portion of income within each bracket is taxed at that bracket's rate).income_tax(50000)
5000.0
0 tax on first 10000, 10% of 30000 (=3000) on the 10000-40000 band, 20% of 10000 (=2000) on the amount above 40000: 3000+2000=5000.0.
income_tax(5000)
0.0
Entirely within the tax-free bracket.
Compute the taxable amount in each band with max(0, min(income, upper) - lower).
The nested function can be a small helper that returns the tax for one bracket, or you can inline the three-band math directly inside income_tax as its own local logic.