我将使用基本运算符制作一个 python 程序来请求用户的收入,以便计算 2017 年和 2018 年的累进税。输出应如下所示:
Income: 15000
2017 tax: (tax amount here) #will skip the math for samples
2018 tax: (tax amount here)
我的程序现在为 2017 / 2018 生成两个打印,但将停止在 2018 嵌套 if 括号 82501 到 157500(嵌套在第 4 个 elif 中)......这是我的程序截至目前,因为它很长我会标出它停止工作的地方。
income = float(input("Enter your income to calculate tax: "))
#Loop input/calculations
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)
我已经标记了行不通的行。只是为了澄清,嵌套的 if 和打印之前的输出 2017 年和 2018 年的结果,但当收入在标记范围内或更大时,只会打印 2017 年的税。
慕婉清6462132
相关分类