Oct-13-2019, 04:08 PM
I am absolutely new to python without any prior programming knowledge. my question is there an easy way to combine the categories given below in an efficient way. instead of writing the same thing over and over again can it be done more efficiently?
#Income Tax Calculation print ("Category of the Tax Payers") print ("---------------------------") print ("1: Single") print ("2: Married Filing Jointly") print ("3: Married Filing Seperately") print ("4: Head of Household") category = eval(input("Please specifiy your category. e.g., 1,2,3,4: ")) income = eval(input("Please enter your income amount. e.g., 90000: ")) if category == 1: a = 8350 b = 33950 c = 82250 d = 171550 e = 372950 if income <= a: tax_amount = income * 0.1 elif income <= b: tax_amount = a * 0.1 + (income-a) * 0.15 elif income <= c: tax_amount = a * 0.1 + b * 0.15 + (income-b) * 0.25 elif income <= d: tax_amount = a * 0.1 + b * 0.15 + c * 0.25 + (income-c) * 0.28 elif income <= e: tax_amount = a*0.1 + b*0.15 + c*0.25+ d*0.28+(income-d)*0.3 else: tax_amount = a*0.1+b*0.15+c*0.25+d*0.28+e*0.3+(income-e)*0.35 print ("Your tax amount is: ",tax_amount) elif category == 2: a = 16700 b = 33950 c = 68525 d = 104425 e = 186475 if income <= a: tax_amount = income * 0.1 elif income <= b: tax_amount = a * 0.1 + (income-a) * 0.15 elif income <= c: tax_amount = a * 0.1 + b * 0.15 + (income-b) * 0.25 elif income <= d: tax_amount = a * 0.1 + b * 0.15 + c * 0.25 + (income-c) * 0.28 elif income <= e: tax_amount = a*0.1 + b*0.15 + c*0.25+ d*0.28+(income-d)*0.3 else: tax_amount = a*0.1+b*0.15+c*0.25+d*0.28+e*0.3+(income-e)*0.35 print ("Your tax amount is: ",tax_amount) elif category == 3: a = 8350 b = 33950 c = 68525 d = 104425 e = 186475 if income <= a: tax_amount = income * 0.1 elif income <= b: tax_amount = a * 0.1 + (income-a) * 0.15 elif income <= c: tax_amount = a * 0.1 + b * 0.15 + (income-b) * 0.25 elif income <= d: tax_amount = a * 0.1 + b * 0.15 + c * 0.25 + (income-c) * 0.28 elif income <= e: tax_amount = a*0.1 + b*0.15 + c*0.25+ d*0.28+(income-d)*0.3 else: tax_amount = a*0.1+b*0.15+c*0.25+d*0.28+e*0.3+(income-e)*0.35 print ("Your tax amount is: ",tax_amount) elif category == 4: a = 11950 b = 45500 c = 117450 d = 190200 e = 372950 if income <= a: tax_amount = income * 0.1 elif income <= b: tax_amount = a * 0.1 + (income-a) * 0.15 elif income <= c: tax_amount = a * 0.1 + b * 0.15 + (income-b) * 0.25 elif income <= d: tax_amount = a * 0.1 + b * 0.15 + c * 0.25 + (income-c) * 0.28 elif income <= e: tax_amount = a*0.1 + b*0.15 + c*0.25+ d*0.28+(income-d)*0.3 else: tax_amount = a*0.1+b*0.15+c*0.25+d*0.28+e*0.3+(income-e)*0.35 print ("Your tax amount is: ",tax_amount) else: print ("Please enter the valid category")