#!/usr/bin/env python3
_PERCENTS   = 0.10, 0.15, 0.25, 0.28, 0.33, 0.35
_THRESHOLDS = 8350, 33950, 82250, 171550, 372950


def compute_tax(income):
    tax = 0
    for percent, threshold, prev_threshold in zip(_PERCENTS, _THRESHOLDS, (0,) + _THRESHOLDS):
        if income <= 0:
            break
        income_part = min(income, threshold - prev_threshold)
        tax += income_part * percent
        income -= income_part
    
    if income > 0:
        tax += income * _PERCENTS[-1]
    
    return tax
    

def main():
    tax = compute_tax(5000.0)
    controlValue = 5000 * 0.10
    print('Tax is',  (tax * 100) / 100.0)
    print('Control value is',  (controlValue * 100) / 100.0)


    tax = compute_tax(10000.0)
    controlValue = 8350 * 0.10 + (10000 - 8350) * 0.15
    print('Tax is',  tax * 100 / 100.0)
    print('Control value is',  (controlValue * 100) / 100.0)


    tax = compute_tax(50000.0)
    controlValue = 8350 * 0.10 + (33950 - 8350) * 0.15 + \
        (50000 - 33950) * 0.25
    print('Tax is',  (tax * 100) / 100.0)
    print('Control value is',  (controlValue * 100) / 100.0)


    tax = compute_tax(100000.0)
    controlValue = 8350 * 0.10 + (33950 - 8350) * 0.15 + \
        (82250 - 33950) * 0.25 + (100000 - 82250) * 0.28
    print('Tax is',  (tax * 100) / 100.0)
    print('Control value is',  (controlValue * 100) / 100.0)


    tax = compute_tax(200000.0)
    controlValue = 8350 * 0.10 + (33950 - 8350) * 0.15 + \
        (82250 - 33950) * 0.25 + (171550 - 82250) * 0.28 + \
        (200000 - 171550) * 0.33
    print('Tax is',  (tax * 100) / 100.0)
    print('Control value is',  (controlValue * 100) / 100.0)


    tax = compute_tax(500000.0)
    controlValue = 8350 * 0.10 + (33950 - 8350) * 0.15 + \
        (82250 - 33950) * 0.25 + (171550 - 82250) * 0.28 + \
        (372950 - 171550) * 0.33 + (500000 - 372950) * 0.35
    print('Tax is',  (tax * 100) / 100.0)
    print('Control value is',  (controlValue * 100) / 100.0)
    
if __name__ == '__main__':
    main()