I am to make a python program using basic operators to ask for an income from the user, in order to calculate the 2017 progressive tax along with 2018. The output should look like this:
Income: 15000
2017 tax: (tax amount here) #will skip the math for samples
2018 tax: (tax amount here)
My program as of now produces both prints for 2017 / 2018 but will stop at the 2018 nested if bracket of 82501 to 157500 (which is nested in the 4th elif)... Here's my program as of now, since its long i'll mark out where it stops working.
income = float(input("Enter your income to calculate tax: "))
while income > 0:
print("----------------------------------------------")
if income >= 0 and income <= 9325:
bracket1 = income * 0.10
tax2017 = bracket1
print("Income: ",income)
print("2017 tax: ",format(tax2017,'.2f'))
if income >= 0 and income <= 9525:
newbracket1 = income * 0.10
tax2018 = newbracket1
print("2018 tax: ",format(tax2018,'.2f'))
income = float(input("\nEnter your income as and integer with no commas: "))
elif income >= 9326 and income <= 37950:
bracket1 = 9325 * 0.10
bracket2 = (income - 9326) * 0.15
tax2017 = bracket1 + bracket2
print("Income: ",income)
print("2017 tax: ",format(tax2017,'.2f'))
if income >= 9526 and income <=38700:
newbracket1 = 9526 * 0.10
newbracket2 = (income - 9525) * 0.12
tax2018 = newbracket1 + newbracket2
print("2018 tax: ",format(tax2018,'.2f'))
income = float(input("\nEnter your income as and integer with no commas: "))
elif income >= 37951 and income <= 91900:
bracket1 = 9325 * 0.10
bracket2 = (37950 - 9325) * 0.15
bracket3 = (income - 37951) * 0.25
tax2017 = bracket1 + bracket2 + bracket3
print("Income: ",income)
print("2017 tax: ",format(tax2017,'.2f'))
if income >= 38701 and income <= 82500:
newbracket1 = 9526 * 0.10
newbracket2 = (38700 - 9526) * 0.12
newbracket3 = (income - 38700) * 0.22
tax2018 = newbracket1 + newbracket2 + newbracket3
print("2018 tax: ",format(tax2018,'.2f'))
income = float(input("\nEnter your income as and integer with no commas: "))
elif income >= 91901 and income <= 191650:
bracket1 = 9325 * 0.10
bracket2 = (37950 - 9325) * 0.15
bracket3 = (91901 - 37950) * 0.25
bracket4 = (income - 91901) * 0.28
tax2017 = bracket1 + bracket2 + bracket3 + bracket4
print("Income: ",income)
print("2017 tax: ",format(tax2017,'.2f'))
if income >= 82501 and income <= 157500: #RIGHT HERE is where "if" doesn't work, unless its a "print" problem
newbracket1 = 9526 * 0.10
newbracket2 = (38700 - 9526) * 0.12
newbracket3 = (82500 - 38701) * 0.22
newbracket4 = (income - 82500) * 0.24
tax2018 = newbracket1 + newbracket2 + newbracket3 + newbracket4
print("2018 tax: ",format(tax2018,'.2f'))
income = float(input("\nEnter your income as and integer with no commas: "))
I've marked the line that wont work. just to clarify, the nested if's and prints before that output both 2017 and 2018 results, but when the income is in the marked range and greater, only 2017's tax will print.
My outcome at income 82502 and above is something like:
Enter your income to calculate tax: 82502
----------------------------------------------
Income: 82502.0
2017 tax: 16364.00
Enter your income as and integer with no commas:
Aucun commentaire:
Enregistrer un commentaire