[英]I cant seem to fix these erros in my code
My assignment is asking me to:我的任务要求我:
Write a program to fetch employee name and the salary.编写一个程序来获取员工姓名和工资。 Calculate the Federal tax and state tax based on the following criteria: If the salary is greater than 100000 then calculate the federal tax at 20% otherwise calculate the federal tax at 15% Calculate the state tax at 5% Calculate the net salary of the employee.根据以下标准计算联邦税和州税: 如果工资大于 100000 则按 20% 计算联邦税,否则按 15% 计算联邦税 按 5% 计算州税 计算员工的净工资. To calculate the net salary, subtract federal and state tax from the gross salary.要计算净工资,请从总工资中减去联邦税和州税。
I have written a program to solve this and it does run/ calculate everything my instructor asked, but I keep getting the same errors, every time I think I've fixed them.我已经编写了一个程序来解决这个问题,它确实运行/计算了我导师要求的所有内容,但是每次我认为我已经修复了它们时,我总是遇到相同的错误。
Here is my code:这是我的代码:
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))
sorry if any of this looks messy, this if my first use of stackoverflow抱歉,如果其中任何一个看起来很乱,这是我第一次使用 stackoverflow
Thank You!谢谢你!
Based on the difference between the correct output and your output, your output is not formatted correctly.根据正确输出和您的输出之间的差异,您的输出格式不正确。 Include a space before every colon ( :
) in every print
statement包括每一个冒号前的空格( :
在每一个) print
声明
According to the test case's output and your output, the only difference is the space you are missing in the print statement.根据测试用例的输出和您的输出,唯一的区别是您在打印语句中缺少的空间。
Try below in every print statement:在每个打印语句中尝试以下操作:
print('Your Federal Tax is :'+str(federal_tax))
Just alter the indentations and spacings.I think your grader throws output for spaces.只需更改缩进和间距。我认为您的分级器会为空格抛出输出。 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))
You'd better replace the +
with a ,
on the print
lines.您最好将print
行上的+
替换为,
。
print("abc" + str(1)) # will print 'abc1'
print("abc", str(1)) # will print 'abc 1'
Using a comma will insert a space automatically.使用逗号将自动插入一个空格。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.