Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- # https://www.facebook.com/groups/learnpython.org/permalink/1181939875203961/
- #
- def calculate_tax(people):
- for key, earning in people.items():
- if earning <= 1000:
- total_tax = 0
- elif earning <= 10000:
- tax1 = 0 #* 1000
- tax2 = 0.1 * (earning - 1000)
- total_tax = tax1 + tax2
- elif earning <= 20200:
- tax1 = 0 #* 1000
- tax2 = 0.1 *9000
- tax3 = 0.15 * (earning - 10000)
- total_tax = tax1+tax2+tax3
- elif earning <= 30750:
- tax1 = 0 #* 1000
- tax2 = 0.1 * 9000
- tax3 = 0.15 * 10200
- tax4 = 0.20 * (earning - 20200)
- total_tax = tax1+tax2+tax3+tax4
- elif earning <= 50000:
- tax1 = 0 #* 1000
- tax2 = 0.1 * 9000
- tax3 = 0.15 * 10200
- tax4 = 0.20 * 10550
- tax5 = 0.25 * (earning - 30750)
- total_tax = tax1+tax2+tax3+tax4+tax5
- else:
- tax1 = 0 #* 1000
- tax2 = 0.1 * 9000
- tax3 = 0.15 * 10200
- tax4 = 0.20 * 10550
- tax5 = 0.25 * 19250
- tax6 = 0.3 * (earning - 50000)
- total_tax = tax1+tax2+tax3+tax4+tax5+tax6
- people[key] = total_tax
- return people
- data = {
- 'Alex': 500,
- 'James': 20500,
- 'Kinuthia': 70000
- }
- calculate_tax(data)
- print(data)
- # ---
- expected_result = {'James': 2490.0, 'Kinuthia': 15352.5, 'Alex': 0}
- assert data == expected, "Different results"
Add Comment
Please, Sign In to add comment