# 147|PYTHON – Tax Array Functions

BYU Student Author: @Trent_Barlow
Reviewers: @Kyle_nilsen, @Millie_K_B
Estimated Time to Solve: 20 Minutes

This is an intro challenge that is part of the Python Learning Path.

We provide the solution to this challenge using:

• Python

Overview
As a beginner Python programmer starting out in the field of accounting, you’ve been tasked with building a program to calculate income tax based on different tax brackets. Your program will utilize NumPy arrays to efficiently store income levels and corresponding tax rates. Additionally, you’ll calculate basic statistics for income and tax rates using NumPy functions.

Instructions

1. Build Function to Calculate Bracket Sizes: Build a Python function named get_bracket_sizes that takes one argument: income_levels, a 1D NumPy array of income amounts corresponding to different tax brackets. Use np.copy to make a copy of the income_levels array called bracket_sizes. Use np.insert, and np.delete to insert a 0 in the front of the new array, then delete the final entry in the new array. Finally, set bracket_sizes equal to income_levels minus bracket_sizes. Have the function return bracket_sizes. Your function can be tested using income_levels. The final figures check is below.
2. Build function to get bracket_taxes: Write a separate function named get_bracket_taxes that takes the bracket_sizes array and the tax_rates array as arguments. You will need to use np.delete on tax_rates to delete the final entry to make the arrays the same size. Then multiply them to make an array called bracket_rates. This is the full amount of taxes paid if one’s income is above the corresponding amount in income_levels. Check figures below:
3. Edit calc_tax function: You have almost finished a function to calculate each individual’s taxes, but it is not working the way you want it to. Edit the function to append each income and tax in a list, to the list “result.” After all results are input, transform result into a 2d np array. Check figures below
Check Figures
1. [11000 33725 50650 86725 49150 346875]

2. [1210. 4047. 11143. 20814. 15728. 121406.25]

3. Income and corresponding tax amount:
[30000. 3490.] [50000. 6417.5] [75000. 11917.5] [100000. 17510.]

Data Files

Solution