我将使用基本运算符制作一个 python 程序来请求用户的收入,以便计算 2017 年和 2018 年的累进税。输出应如下所示:Income: 150002017 tax: (tax amount here) #will skip the math for samples2018 tax: (tax amount here)我的程序现在为 2017 / 2018 生成两个打印,但将停止在 2018 嵌套 if 括号 82501 到 157500(嵌套在第 4 个 elif 中)......这是我的程序截至目前,因为它很长我会标出它停止工作的地方。income = float(input("Enter your income to calculate tax: "))#Loop input/calculationswhile 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)我已经标记了行不通的行。只是为了澄清,嵌套的 if 和打印之前的输出 2017 年和 2018 年的结果,但当收入在标记范围内或更大时,只会打印 2017 年的税。
1 回答
慕婉清6462132
TA贡献1804条经验 获得超2个赞
只需解决程序将通过的语句
income = 82502.0
将进入
elif income >= 37951 and income <= 91900:
但是对于2018年的计算,它不会满足里面的条件
if income >= 38701 and income <= 82500:
所以它没有办法计算2018。它不会到达你标记它的地步。
2017 年的计算应独立于 2018 年的计算。在很多情况下,您的计算不会打印 2018 年的税款。
但是您确实进行了很好的测试,可以看到您的程序无法正常工作。边缘情况通常会带来问题。
添加回答
举报
0/150
提交
取消