【问题标题】:I cant seem to fix these erros in my code我似乎无法在我的代码中修复这些错误
【发布时间】:2020-03-07 05:21:13
【问题描述】:

我的任务要求我:

编写一个程序来获取员工姓名和工资。根据以下标准计算联邦税和州税: 如果工资大于 100000 则按 20% 计算联邦税 否则按 15% 计算联邦税 按 5% 计算州税 计算员工的净工资.要计算净工资,请从总工资中减去联邦和州税。

我已经编写了一个程序来解决这个问题,它确实会运行/计算我的导师要求的所有内容,但每次我认为我已经修复了它们时,我都会遇到同样的错误。

这是我的代码:

your_name = input('Please enter your name:')
employee_salary = int(input('Please enter your salary:'))
if employee_salary >= 100000:
    federal_tax = (employee_salary *20) / 100
    state_tax = (employee_salary * 5) / 100
    net_salary = employee_salary - state_tax - federal_tax
    print('Your Federal Tax is:'+str(federal_tax))
    print('Your State Tax is:'+str(state_tax))
    print('Your net salary is:'+str(net_salary))
else:
    employee_salary < 100000
    federal_tax = (employee_salary * 15) / 100
    state_tax = (employee_salary * 5) / 100
    net_salary = employee_salary - state_tax - federal_tax
    print('Your Federal Tax is:'+str(federal_tax))
    print('Your State Tax is:'+str(state_tax))
    print('Your net salary is:'+str(net_salary))

对不起,如果这看起来很乱,这是我第一次使用 stackoverflow

谢谢!

My code errors

【问题讨论】:

    标签: python


    【解决方案1】:

    根据正确输出和您的输出之间的差异,您的输出格式不正确。在每个 print 语句中的每个冒号 (:) 前包含一个空格

    【讨论】:

      【解决方案2】:

      根据测试用例的输出和你的输出,唯一的区别就是你在print语句中少了空格。

      在每个打印语句中尝试以下操作:

      print('Your Federal Tax is :'+str(federal_tax))
      

      【讨论】:

        【解决方案3】:

        只需更改缩进和间距。我认为您的评分器会输出空格。 your_name = input('Please enter your name :') employee_salary = int(input('Please enter your salary :')) if employee_salary >= 100000: federal_tax = (employee_salary)*0.2 state_tax = (employee_salary)*0.5 net_salary = employee_salary -(state_tax + federal_tax) print('Your Federal Tax is :'+str(federal_tax)) print('Your State Tax is :'+str(state_tax)) print('Your net salary is :'+str(net_salary)) else: employee_salary < 100000 federal_tax = (employee_salary *0.15) state_tax = (employee_salary *0.05) net_salary = employee_salary -(state_tax + federal_tax) print('Your Federal Tax is :'+str(federal_tax)) print('Your State Tax is :'+str(state_tax)) print('Your net salary is :'+str(net_salary))

        【讨论】:

          【解决方案4】:

          您最好在print 行上将+ 替换为,。

          print("abc" + str(1)) # will print 'abc1'
          print("abc", str(1))  # will print 'abc 1'
          

          使用逗号会自动插入空格。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2021-05-13
            • 2022-01-02
            • 1970-01-01
            相关资源
            最近更新 更多