Question: I am writing a program for my computer science class that is supposed to calculate the difference between the 2017 and 2017 tax brackets. The
I am writing a program for my computer science class that is supposed to calculate the difference between the 2017 and 2017 tax brackets. The input numbers will be 100000 and 500000. For some reason my calculations are outputting the wrong number, and I am not sure why. My code is as follows:
income = float(input("Enter income as an integer with no commas: "))
while income >= 0: #Calculate the old tax brackets if income <= 9325: old = float(income * 0.10) if income in range (9326,37950): old = float(((income-9325)*0.15)+932.50) if income in range (37951,91900): old = float(((income-37950)*0.25)+5226.25) if income in range (91901,191650): old = float(((income-91900)*0.28)+18713.75) if income in range (191651,416700): old = float(((income-191650)*0.33)+46643.75) if income in range (416701,418400): old = float(((income-416700)*0.35)+120910.25) if income > 41401: old = float(((income-418400)*0.396)+121505.25) #Calculate the new tax brackets if income <= 9525: new = float(income * 0.10) if income in range (9526,38700): new = float(((income-9525)*0.12)+952.50) if income in range (38701,82500): new = float(((income-38700)*0.22)+4453.50) if income in range (82501,157500): new = float(((income-82500)*0.24)+14089.50) if income in range (157501,200000): new = float(((income-157500)*0.32)+32089.50) if income in range (200001,500000): new = float(((income-200000)*0.35)+45689.50) if income > 500000: new = float(((income-500000)*0.37)+150689.50) #Compare the tax brackets if (new - old) == 0: difference = 0.0 else: difference = float(new - old) if difference == 0.0: percent = 0.0 else: percent = float(((abs(difference))/old)*100) #Print results print ("Income: ", round (income,2)) print ("2017 tax: ", round (old,2)) print ("2018 tax: ", round (new,2)) print ("Difference: ", round (difference,2)) print ("Difference (percent): ", round (percent,2)) income = int(input("Enter income as an integer with no commas: "))
The correct output for 100000 should be:
2017 tax: 20981.75 2018 tax: 18289.5 Difference: -2692.25 Difference (percent): 12.83
and for 500000 it should be: 2017 tax: 153818.85 2018 tax: 150689.5 Difference: -3129.35 Difference (percent): 2.03
For 100000, my program is returning: 2017 tax: 153818.85 2018 tax: 150689.5 Difference: -3129.35 Difference (percent): 2.03
and for 500000 its returning: 2017 tax: 153818.85 2018 tax: 150689.5 Difference: -3129.35 Difference (percent): 2.03
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
