Progressive Tax Bracket Calculator

Hard ⏱ 18 min 35% acceptance ★★★★★ 4.5
Write a function income_tax(income) that computes tax using progressive brackets: 0% on the first 10,000, 10% on the portion from 10,000 to 40,000, 20% on the portion from 40,000 to 100,000, and 30% on anything above 100,000. Return the total tax owed as a number. For example, someone earning 50,000 pays 0 on the first 10,000, 10% of 30,000 (=3,000) on the next slice, and 20% of 10,000 (=2,000) on the remainder, totaling 5,000.

Examples

Example 1
Input
income_tax(50000)
Output
5000
Explanation

0 + 3000 (10% of 30000) + 2000 (20% of 10000).

Example 2
Input
income_tax(5000)
Output
0
Explanation

Entirely within the 0% bracket.

Example 3
Input
income_tax(150000)
Output
30000
Explanation

0 + 3000 (10% of 30000) + 12000 (20% of 60000) + 15000 (30% of 50000) = 30000.

Constraints

  • income is a non-negative number.

Topics

Conditional StatementsBusiness Logicnested conditionals

Companies

Goldman SachsDeutsche BankJPMorgan Chase

Hints

Hint 1

Use if/elif on which bracket the income falls into, then compute the tax for each slice below it.

Hint 2

Careful: each bracket only taxes the portion of income that falls within it, not the whole income.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.