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: 1000) * 0.1
Yearly Income: 10,001 - 20,200; Tax: (YI - 900
Yearly Income: 20,201 - 30,750; Tax: (YI - 2430
Yearly Income: 30,751 - 50,000; Tax: (YI - 4540
Yearly Income: Over 50,000; Tax: (YI - 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 dExamples:
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