我不知道我的条件语句有什么问题

I don't know what is wrong with my condition statements

它不起作用,这就是我正在尝试做的。

找出一个人的税并根据他们的身份和家属减去一些我的预期输出是用户将输入其收入然后乘以将扣除多少税并且还会扣除一些根据他们的身份和有多少家属

他们有:

Income: 500000
Status: Married
Dependents= 3   
Tax = 25000
income = float(input("your income: "))
if income <= 100000:
    initialIncome = income * .5 
elif income in range (100001,250000):
    initialIncome = income * .10
elif income in range (250001,500000):
    initialIncome = income * .15
elif income >= 500001:
    initialIncome = income * .20

status = input("status (s,m,w,d) ")
if status == "S":
    S = 10000
elif status == "M":
    S = 20000
elif status == "W":
    S = 10000
elif status == "D":
    S = 30000

dependents = float(input("dependents num: "))
if dependents >= 5:
    dependentsPrice = 50000
if dependents <= 5:
    dependentsPrice = 10000 * dependents


totalTax = initialIncome - (status + dependents)

print(totalTax)

代码:

  • 您使用的是 totalTax 中的状态而不是 S
  • 您必须添加 .upper() 以将所有输入字符串转换为大写,因为您在 if statements.
  • 中使用了大写
income = float(input("your income: "))
if income <= 100000:
    initialIncome = income * .5 
elif income in range (100001,250000):
    initialIncome = income * .10
elif income in range (250001,500001):
    initialIncome = income * .15
elif income >= 500001:
    initialIncome = income * .20
else:
    print("Invalid input")
    initaialIncome = 0


# Here you must add upper to convert all the strings to upper case
status = input("status (s,m,w,d) ").upper()
#To prevent undefined error
S = 
if status == "S":
    S = 10000
elif status == "M":
    S = 20000
elif status == "W":
    S = 10000
elif status == "D":
    S = 30000
#In case user enters wrong input.
else:
    print("Invalid input")


dependents = float(input("dependents num: "))
if dependents >= 5:
    dependentsPrice = 50000 *dependents
if dependents <= 5:
    dependentsPrice = 10000 * dependents

# Here status is string. I suppose you are trying to use S.
#here use dependsPrice
totalTax = initialIncome - (S + dependentsPrice) 

print(totalTax)