#!/usr/bin/env python3
# -- coding: utf-8 --
# @Date : 2018-07-12 16:14:53
# @Author : Simon (simon.xie@codewalker.meg)
# @Link : http://www.codewalker.me
# @Version : 1.0.0

import sys, bisect

def tax_calculator(income):
if income < 5000:
return 0.0
above = income - 5000
ranges = [ 0, 1500, 4500, 9000, 35000, 55000, 80000 ]
rate = [ .03, .1, .2, .25, .30, .35, .45 ]
i = bisect.bisect_left(ranges, above)
j = 0
tax = 0.0
while j < i:
if j + 1 < i:
tax += (ranges[j+1]-ranges[j])*rate[j]
else:
tax += (above-ranges[j]) * rate[j]
j += 1
return tax
def main(income):
tax = tax_calculator(income)
print(‘Tax is {}’.format(tax))

if __name__ == “__main__“:
if len(sys.argv) < 2:
print(‘Usage: {} ‘.format(sys.argv[0]))
sys.exit(1)
main(float(sys.argv[1]))