Question #63759

Country X calculates tax for its citizens using a graduated scale rate as shown below:

Yearly Income: 0 - 1000

Tax Rate: 0%

Yearly Income: 1,001 - 10,000

Tax Rate: 10%

Yearly Income: 10,001 - 20,200

Tax Rate: 15%

Yearly Income: 20,201 - 30,750

Tax Rate: 20%

Yearly Income: 30,751 - 50,000

Tax Rate: 25%

Yearly Income: Over 50,000

Tax Rate: 30%

Write a Python function named calculate_tax that will take as an argument, a dictionary containing key-value pairs of people's names as the keys and their yearly incomes as the values.

Expert's answer

Answer on Question#63759 – Programming & Computer Science | Python


def calculate_tax(incomes):
    return {name: income * min([rate
        for edge, rate in {
            1000: 0,
            10000: 10,
            20200: 15,
            30750: 20,
            50000: 25
        }.iteritems()
        if income <= edge] + [30])/100.0
        for name, income in incomes.iteritems()}
ilist = {"Jonh": 500, "Mary": 22000, "Mark": 51000}
print calculate_tax(ilist)


http://www.AssignmentExpert.com

LATEST TUTORIALS
APPROVED BY CLIENTS