Answer to Question #64360 in Python for Solomon

Question #64360
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:

{
‘Alex’: 500,
‘James’: 20500,
‘Kinuthia’: 70000
}
The output would be as follows:

{
‘Alex’: 0,
‘James’: 2490,
‘Kinuthia’: 15352.5
}
1
Expert's answer
2017-01-04T04:19:50-0500
def get_tax(income):
total_tax = 0
incs = [0, 1000, 10000, 20200, 30750, 50000, 2e9]
tx = [0, 0.1, 0.15, 0.2, 0.25, 0.3]
for i in range(1, len(incs)):
money = min(incs[i] - incs[i-1], income - incs[i-1])
if money < 0: break
total_tax += tx[i-1] * money
return total_tax


def calculate_tax(people):
tax = dict(people)
for x in tax:
tax[x] = get_tax(tax[x])
return tax

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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS