为什么输出“ Value Error”显示在我的代码中?

时间:2019-08-12 00:04:12

标签: python

我是python的新手,并构建了一个简单的州税计算器。 我使用了一个大函数以及if,elif和else语句。

我已经包含了每种状态的输入和公式。

def state_tax_calculator():
    s = input(("Hello! What state do you live in? "))
    n = int(input(("What was your income, in dollars, this year? ")))

    if s.title() == "Alabama":
        x = n*0.04
        y = n-(n*0.04)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "Alaska":
        return "Lucky for you, there is no state tax in your state!"
    elif s.title() == "Arizona":
        x = n*0.056
        y = n-(n*0.056)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "Arkansas":
        x = n*0.065
        y = n-(n*0.65)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "California":
        x = n*0.0725
        y = n-(n*0.0725)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "Colorado":
        x = n*0.029
        y = n-(n*0.029)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "Conneticut":
        x = n*0.0635
        y = n-(n*0.0635)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "Delaware":
        x = n*0.0474
        y = n-(n*0.0474)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "Florida":
        x = n*0.06
        y = n-(n*0.06)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "Georgia":
        x = n*0.04
        y = n-(n*0.04)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "Hawaii":
        x = n*0.04
        y = n-(n*0.04)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "Idaho":
        x = n*0.06
        y = n-(n*0.06)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "Illinois":
        x = n*0.0625
        y = n-(n*0.0625)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "Indiana":
        x = n*0.07
        y = n-(n*0.07)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "Iowa":
        x = n*0.06
        y = n-(n*0.06)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "Kansas":
        x = n*0.065
        y = n-(n*0.065)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "Kentucky":
        x = n*0.06
        y = n-(n*0.06)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "Louisiana":
        x = n*0.0445
        y = n-(n*0.0445)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "Maine":
        x = n*0.055
        y = n-(n*0.055)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "Maryland":
        x = n*0.06
        y = n-(n*0.06)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "Massachusetts":
        x = n*0.0625
        y = n-(n*0.0625)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "Michigan":
        x = n*0.06
        y = n-(n*0.06)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "Minnesota":
        x = n*0.0688
        y = n-(n*0.0688)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "Mississippi":
        x = n*0.07
        y = n-(n*0.07)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "Missouri":
        x = n*0.0423
        y = n-(n*0.0423)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "Montana":
        x = n*0.0461
        y = n-(n*0.0461)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "Nebraska":
        x = n*0.055
        y = n-(n*0.055)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "Nevada":
        x = n*0.0685
        y = n-(n*0.0685)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "New Hampshire":
        return "Lucky for you, there is no state tax in your state!"
    elif s.title() == "New Jersey":
        x = n*0.0663
        y = n-(n*0.0663)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "New Mexico":
        x = n*0.0513
        y = n-(n*0.0513)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "New York":
        x = n*0.04
        y = n-(n*0.04)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "North Carolina":
        x = n*0.0475
        y = n-(n*0.0475)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "North Dakota":
        x = n*0.05
        y = n-(n*0.05)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "Ohio":
        x = n*0.0575
        y = n-(n*0.0575)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "Oklahoma":
        x = n*0.045
        y = n-(n*0.045)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "Oregon":
        x = n*0.0725
        y = n-(n*0.0725)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "Pennsylvania":
        x = n*0.06
        y = n-(n*0.06)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "Rhode Island":
        x = n*0.07
        y = n+(n*0.07)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "South Carolina":
        x = n*0.06
        y = n-(n*0.06)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "South Dakota":
        x = n*0.045
        y = n-(n*0.045)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "Tennessee":
        x = n*0.07
        y = n-(n*0.07)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "Texas":
        x = n*0.0625
        y = n-(n*0.0625)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "Utah":
        x = n*0.0595
        y = n-(n*0.0595)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "Vermont":
        x = n*0.06
        y = n-(n*0.06)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "Virginia":
        x = n*0.053
        y = n-(n*0.053)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "Washington":
        x = n*0.065
        y = n-(n*0.065)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "West Virginia":
        x = n*0.06
        y = n-(n*0.06)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "Wisconsin":
        x = n*0.05
        y = n-(n*0.05)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "Wyoming":
        x = n*0.04
        y = n-(n*0.04)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    elif s.title() == "District Of Columbia":
        x = n*0.06
        y = n-(n*0.06)
        return f"Your state tax cost, in dollars, is {x}."
        return f"Your income after the state tax, in dollars, is {y}."
    else:
        return input(("That is not a state, please enter a state: "))

我希望: “以美元为单位的州税成本为_。”和“以美元为单位的州税后收入为_。”

但是,我还是遇到了ValueError,说“以10为底的int()的无效文字:'200,000'”  或仅返回上面的第一条语句。

谢谢你, 西奥·托贝尔

2 个答案:

答案 0 :(得分:1)

  

“ int()以10为底的无效文字:'200,000'”

这意味着您的输入语句不能转换为整数。这是因为您的逗号为200,000。将其更改为200000

答案 1 :(得分:1)

您在200,000中有一个逗号,因此不能将其转换为int。删除逗号。如果希望将它们分开以提高可读性,也可以在Python中进行200_000