Created
September 3, 2016 15:50
-
-
Save ooade/787c53fe18ae07c59901f3b187f42622 to your computer and use it in GitHub Desktop.
Tax Rate Challenge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def calculate_tax(names): | |
| try: | |
| new_dict = {} | |
| for name in names: | |
| a = [0, 1000, 10000, 20200, 30750, 50000] | |
| b = [1000, 10000, 20200, 30750, 50000, 100000] | |
| p = [0, .1, .15, .2, .25, .3] | |
| amount = names[name] | |
| tax = 0 | |
| i = 0 | |
| while amount > 0: | |
| rate = b[i] - a[i] | |
| if (amount < rate and i != 5): | |
| tax += (amount * p[i]) | |
| amount = 0 | |
| i += 1 | |
| elif i != 5: | |
| tax += (rate * p[i]) | |
| amount -= rate | |
| i += 1 | |
| else: | |
| # Last elem | |
| if (amount < rate): | |
| tax += (amount * p[i]) | |
| amount = 0 | |
| else: | |
| tax += (0.3 * 50000) | |
| amount -= rate | |
| i = 5 | |
| new_dict[name] = tax | |
| return new_dict | |
| except (AttributeError,TypeError): | |
| raise ValueError('The provided input is not a dictionary') | |
| print(calculate_tax({ | |
| 'Alex': 500, | |
| 'James': 20500, | |
| 'Kinuthia': 70000 | |
| })) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment