The tax calculator program of the case study outputs a floating-point number that might show more than two digits of precision.






Use the round function to modify the program to display at most two digits of precision in the output number.






Below is an example of the program input and output:






Enter the gross income: 12345.67





Enter the number of dependents: 1






The income tax is $-130.87

Respuesta :

Answer:

TAX_RATE = 0.20

STANDART_DEDUCTION = 10000.0

DEPENDENT_DEDUCTION = 3000.0

gross_income = float(input("Enter the gross income: "))

number_of_dependents = int(input("Enter the number of dependents: "))

income = gross_income - STANDART_DEDUCTION - (DEPENDENT_DEDUCTION * number_of_dependents)

tax = income * TAX_RATE

print ("The income tax is $" + str(round(tax, 2)))

Explanation:

Define the constants

Ask user to enter the gross income and number of dependents

Calculate the income using formula (income = gross_income - STANDART_DEDUCTION - (DEPENDENT_DEDUCTION * number_of_dependents))

Calculate the tax

Print the tax

round(number, number of digits) -> This is the general usage of the round function in Python.

Since we need two digits of precision, we need to modify the program as str(round(incomeTax, 2)).