Problem 154492 · medium · Phase 01 Prerequisites & Setup

Progressive Income Tax

conditionals · arithmetic

A country taxes yearly income in brackets. Only the part of the income that falls inside a bracket is taxed at that bracket's rate:

  • the first 10,000: 0%
  • from 10,000 up to 40,000: 10%
  • from 40,000 up to 100,000: 20%
  • everything above 100,000: 30%

Write income_tax(income) that returns the total tax as a float rounded to 2 decimal places.

Examples

Input:  income = 8000
Output: 0.0

Input:  income = 25000
Output: 1500.0
Explanation: only the 15,000 above 10,000 is taxed, at 10%.

Input:  income = 150000
Output: 30000.0
Explanation: 0 + 3000 (10% of 30,000) + 12000 (20% of 60,000) + 15000 (30% of 50,000).

Constraints

  • 0 <= income <= 10**7

Goals

  • Understand that only the income inside a bracket is taxed at that rate
  • Build up a total across several if branches
  • Round money to two decimals
Starting Python…