Skip to content

Instantly share code, notes, and snippets.

@saleem-mirza
Created February 9, 2019 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saleem-mirza/8d1ad3ff192df7e145600b29f6afe49b to your computer and use it in GitHub Desktop.
Save saleem-mirza/8d1ad3ff192df7e145600b29f6afe49b to your computer and use it in GitHub Desktop.
Facebook coding challenge
level = [
[10000,0.1],
[20000,0.2],
[10000,0.1],
[None, 0.4]
]
def calculate_tax(level, income):
if income <= 0:
return (0, 0)
if level[0] is None:
return (0, income * level[1])
if income > level[0]:
income = income - level[0]
return (income, level[0] * level[1])
else:
return (0, income * level[1])
def calculate(level, income):
total_tax = 0.0
for l in level:
income, tax = calculate_tax(l, income)
total_tax += tax
return total_tax
incomes = [-1, 0, 10, 10000, 15000.75, 21000, 41000, 50000]
taxes = [calculate(level, income) for income in incomes]
print(taxes)
# [0.0, 0.0, 1.0, 1000.0, 2000.15, 3200.0, 6400.0, 10000.0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment