Question #62196

TAX LAB
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.

The function should return a dictionary containing key-value pairs of the same people’s names as keys and their yearly tax bill as the values. For example, given the sample input below:

{

Expert's answer

Answer on Question #62196, Programming & Computer Science / Python

TAX LAB

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.

The function should return a dictionary containing key-value pairs of the same people's names as keys and their yearly tax bill as the values. For example, given the sample input below:

Answer:

The tax may be calculated by the formula:

Yearly Income: 0 - 1000; Tax: 0YearlyIncome:1,00110,000;Tax:(YI0 Yearly Income: 1,001 - 10,000; Tax: (YI -1000) * 0.1

Yearly Income: 10,001 - 20,200; Tax: (YI - 10000)0.15+10000) * 0.15 +900

Yearly Income: 20,201 - 30,750; Tax: (YI - 20200)0.2+20200) * 0.2 +2430

Yearly Income: 30,751 - 50,000; Tax: (YI - 30750)0.25+30750) * 0.25 +4540

Yearly Income: Over 50,000; Tax: (YI - 50000)0.3+50000) * 0.3 +9352.50

The program:


def calculate_tax(d):
    for i in d:
        if d[i] <= 1000:
            d[i] = 0
        elif d[i] <= 10000:
            d[i] = (d[i]-1000) * 0.1
        elif d[i] <= 20200:
            d[i] = (d[i]-10000) * 0.15 + 900
        elif d[i] <= 30750:
            d[i] = (d[i]-20200) * 0.2 + 2430
        elif d[i] <= 50000:
            d[i] = (d[i]-30750) * 0.25 + 4540
        else:
            d[i] = (d[i]-50000) * 0.3 + 9352.5
    return d

Examples:

print(calculate_tax({"John": 40000, "Sarah": 20000, "Peter": 1000}))
{'John': 6852.5, 'Sarah': 2400.0, 'Peter': 0}

Screenshots:

1~ def calculate_tax (d):
2~ for i in d:
3~ if d[i] <= 1000:
4 d[i] = 0
5~ elif d[i] <= 10000:
6 d[i] = (d[i]-1000) * 0.1
7~ elif d[i] <= 20200:
8 d[i] = (d[i]-10000) * 0.15 + 900
9~ elif d[i] <= 30750:
10 d[i] = (d[i]-20200) * 0.2 + 2430
11~ elif d[i] <= 50000:
12 d[i] = (d[i]-30750) * 0.25 + 4540
13~ else:
14 d[i] = (d[i]-50000) * 0.3 + 9352.5
15 return (d)


http://www.AssignmentExpert.com

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS