231k views
5 votes
This lab will be available until February 23rd, 11:59 PM EST Program Specifications Write a program to calculate U.S. income tax owed given wages, taxable interest, unemployment compensation, status (dependent, single, or married), and taxes withheld. Dollar amounts are displayed as integers with comma separators. For example, print(f"Deduction: ${deduction:,}"). Note: this program is designed for incremental development. Complete each step and submit for grading before starting the next step. Only a portion of tests pass after each step but confirm progress. Step 1. Within the main portion of the code, input the wages, taxable interest, unemployment compensation, status (0=dependent, 1=single, and 2=married), and taxes withheld. Step 2 (2 pts). Complete the calc_AGI() function. Calculate the adjusted gross income (AGI) that is the sum of wages, interest, and unemployment. Convert any negative values to positive before summing to correct potential input errors. Return the AGI. Note the provided code in the main portion of the code calls calc_AGI() and outputs the returned value. Submit for grading to confirm two tests pass. Ex: If the input is: 20000 23 500 1 400 The output is: AGI: $20,523 Step 3 (2 pts). Complete the get_deduction() function. Return the deduction amount based on status: (0) dependent = 6000, (1) single = 12000, or (2) married=24000. Return 6000 if the status is anything but 0, 1, or 2. Within the main portion of the code call get_deduction() and output the returned value. Submit for grading to confirm four tests pass. Ex: If the input is: 20000 23 500 1 400 The additional output is: AGI: $20,523 Deduction: $12,000 Step 4 (2 pts). Complete the calc_taxable function. Calculate taxable amount (AGI - deduction). Set taxable to zero if calculation results in negative value. Return taxable value. Within the main portion of the code call calc_taxable and output the returned value. Submit for grading to confirm six tests pass. Ex: If the input is: 20000 23 500 1 400 The additional output is: AGI: $20,523 Deduction: $12,000 Taxable income: $8,523 Step 5 (2 pts). Complete the calc_tax() function. Calculate tax amount based on status and taxable income (see tables below). Tax amount should be stored initially as a double,then rounded to the nearest whole number using round(). Within the main portion of the code call calc_tax() and output the returned value. Submit for grading to confirm eight tests pass. Ex: If the input is: 50000 0 0 2 5000 The additional output is: AGI: $50,000 Deduction: $24,000 Taxable income: $26,000 Federal tax: $2,720 Step 6 (2 pts). Complete the calc_tax_due() function. Set withheld parameter to zero if negative to correct potential input error. Calculate and return amount of tax due (tax - withheld). Within the main portion of the code call calc_tax_due() and output returned value. Submit for grading to confirm all tests pass. Ex: If the input is: 80000 0 500 2 12000 The additional output is: AGI: $80,500 Deduction: $24,000 Taxable income: $56,500 Federal tax: $6,380 Tax due: $-5,620 what is the correct code that doesn't give an error at the zybook?

User Janisha
by
8.2k points

1 Answer

5 votes

Below is the Python code that follows the specifications provided.

def calc_AGI(wages, interest, unemployment):

# Convert negative values to positive

wages = abs(wages)

interest = abs(interest)

unemployment = abs(unemployment)

# Calculate AGI

agi = wages + interest + unemployment

return agi

def get_deduction(status):

# Deduction based on status

if status == 0: # dependent

return 6000

elif status == 1: # single

return 12000

elif status == 2: # married

return 24000

else:

return 6000 # default deduction for invalid status

def calc_taxable(agi, deduction):

# Calculate taxable income

taxable = max(0, agi - deduction)

return taxable

User Anup Agrawal
by
8.3k points