Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python I';I’’我试图得到我打印的内容,并将其添加到列表中,作为员工工资单打印出来_Python_Python 3.x_List - Fatal编程技术网

Python I';I’’我试图得到我打印的内容,并将其添加到列表中,作为员工工资单打印出来

Python I';I’’我试图得到我打印的内容,并将其添加到列表中,作为员工工资单打印出来,python,python-3.x,list,Python,Python 3.x,List,我试图制作一个列表,从用户那里获取输入,并将其添加到列表中,以便在用户要求时打印,作为python简介类期末考试的一部分。该程序应该是一个工资计算器 我已经尝试创建一个名为employees的空列表,并将打印输出附加到列表中,但它不接受用户输入 employees = [] while yes_no == 1: emp_name = str(input("please enter the employees name")) num1 = int(input("Please en

我试图制作一个列表,从用户那里获取输入,并将其添加到列表中,以便在用户要求时打印,作为python简介类期末考试的一部分。该程序应该是一个工资计算器

我已经尝试创建一个名为employees的空列表,并将打印输出附加到列表中,但它不接受用户输入

employees = []

while yes_no == 1:
    emp_name = str(input("please enter the employees name"))
    num1 = int(input("Please enter the hours you worked "))
    num2 = int(input("Please enter your hourly wage  "))
    print("Employee", emp_name, "Worked ", num1, "hours, and are paid", num2, "$ per hour. Making your salary",
    num1 * num2, "$")
    employees.append("Employee", emp_name, "Worked ", num1, "hours, and are paid", num2,
                     "$ per hour. Making your salary",
                     num1 * num2, "$")

    yes = int(input("If you would like to calculate more employees salaries yes or no "))
    emp_name = str(input("please enter the employees name"))
    num1 = int(input("Please enter the hours you worked "))
    num2 = int(input("Please enter your hourly wage  "))
    print("Employee", emp_name, "Worked ", num1, "hours, and are paid", num2, "$ per hour. Making your salary"
    , num1 * num2, "$")
    employees.append(str("Employee", emp_name, "Worked ", num1, "hours, and are paid", num2,
                     "$ per hour. Making your salary",
                     num1 * num2, "$"))
    yes_no = int(input("If you would like to calculate more employees salaries type 1 for yes or or type 0 for no "))

    if yes_no == 0:
        break

print("Thanks for using my calculator, ", name)
我希望列表中会充满输入,但我的IDE说append需要1个参数,它得到了9位

employees.append("Employee", emp_name, "Worked ", num1, "hours, and are paid", num2,
                 "$ per hour. Making your salary",
                 num1 * num2, "$")
正在尝试使用9个不同的数据段(每个数据段由一个
分隔)调用
append
。如果您想知道
print
如何获取由
分隔的多个对象并将它们连接起来,这是
print
和其他一些函数特有的行为<代码>追加的行为不是这样的

您需要将该数据格式化为一个字符串。这是最简单的方法:

employees.append(f"Employee {emp_name} worked {num1} hours, and are paid {num2} $ per hour."
                 f"Making your salary {num1 * num2} $")
现在,列表中添加了一个字符串


还要注意,您需要对位进行类似的更改

employees.append(str("Employee", emp_name, "Worked ", num1, "hours, and are paid", num2,
                     "$ per hour. Making your salary",
                     num1 * num2, "$"))
str
也不接受那么多参数

我建议您放慢速度,边走边测试代码。当你不确定哪种方法有效时,写大量的文章只会让你头疼,阻碍你的学习