Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/341.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.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中无法正常工作时出现问题 empmangpro=True 雇员=[] 当empmangpro==True时: 尝试: empcount=len(员工) 打印(“--------------员工管理系统------------------”) 打印(“”) 打印(“系统中有”+str(empcount)+“员工”) 打印(“”) 打印(“---------------------------------------------------------------------------”) 打印(“1.添加新员工”) 打印(“2.查看所有员工”) programselection=int(输入(“请选择您的选项号:”) 如果programselection==1: 雇员=[] append(输入(“名字和姓氏:”) employee.append(输入(“社会保险号:”) employee.append(输入(“电话号码:”) employee.append(输入(“电子邮件地址:”) employee.append(输入(“工资:$”) employees.append(雇员) elif programselection==2: i=0 j=0 empstr=“” 当i_Python_Loops_Error Handling - Fatal编程技术网

程序在python中无法正常工作时出现问题 empmangpro=True 雇员=[] 当empmangpro==True时: 尝试: empcount=len(员工) 打印(“--------------员工管理系统------------------”) 打印(“”) 打印(“系统中有”+str(empcount)+“员工”) 打印(“”) 打印(“---------------------------------------------------------------------------”) 打印(“1.添加新员工”) 打印(“2.查看所有员工”) programselection=int(输入(“请选择您的选项号:”) 如果programselection==1: 雇员=[] append(输入(“名字和姓氏:”) employee.append(输入(“社会保险号:”) employee.append(输入(“电话号码:”) employee.append(输入(“电子邮件地址:”) employee.append(输入(“工资:$”) employees.append(雇员) elif programselection==2: i=0 j=0 empstr=“” 当i

程序在python中无法正常工作时出现问题 empmangpro=True 雇员=[] 当empmangpro==True时: 尝试: empcount=len(员工) 打印(“--------------员工管理系统------------------”) 打印(“”) 打印(“系统中有”+str(empcount)+“员工”) 打印(“”) 打印(“---------------------------------------------------------------------------”) 打印(“1.添加新员工”) 打印(“2.查看所有员工”) programselection=int(输入(“请选择您的选项号:”) 如果programselection==1: 雇员=[] append(输入(“名字和姓氏:”) employee.append(输入(“社会保险号:”) employee.append(输入(“电话号码:”) employee.append(输入(“电子邮件地址:”) employee.append(输入(“工资:$”) employees.append(雇员) elif programselection==2: i=0 j=0 empstr=“” 当i,python,loops,error-handling,Python,Loops,Error Handling,我有选项1,您可以向系统中添加多个员工,但当我选择选项2时,什么也没有发生。它应该打印我添加的所有员工。我做错了什么?我只做了不到一个月的编程,所以我还有很多东西要学。我遗漏了什么或做错了什么?您说过选项1有效。好(我看到一些缩进问题) 对于选项2,老实说,我没有完全遵循您的代码。如果希望选项2打印所有员工,我建议创建一个Employee类。这样,您就可以在任何地方打印(员工) 可以将其放入employee.py: empmangpro = True employee

我有选项1,您可以向系统中添加多个员工,但当我选择选项2时,什么也没有发生。它应该打印我添加的所有员工。我做错了什么?我只做了不到一个月的编程,所以我还有很多东西要学。我遗漏了什么或做错了什么?

您说过选项1有效。好(我看到一些缩进问题)

对于选项2,老实说,我没有完全遵循您的代码。如果希望选项2打印所有员工,我建议创建一个
Employee
类。这样,您就可以
在任何地方打印(员工)

可以将其放入
employee.py

       empmangpro = True
       employees = []
       while empmangpro == True:
             try:
                 empcount = len(employees)
                 print("--------------------Employee Management System--------------------")
                 print("")
                 print("There are "+str(empcount)+" employees in the system.")
                 print("")
                 print("------------------------------------------------------------------")

                 print("1. Add new employee")
                 print("2. View all employees")
                 programselection = int(input("Please select your option number: "))

                 if programselection == 1:
                 employee = []
                 employee.append(input("First and Last Name: "))
                 employee.append(input("Social Security Number: "))
                 employee.append(input("Phone Number: "))
                 employee.append(input("Email Address: "))
                 employee.append(input("Salary:$"))
                 employees.append(employee)
                 elif programselection == 2:
                      i = 0
                      j = 0
                      empstr = ""
                      while i < int(empcount):
                          while j < 5:
                             empstr = empstr + employees[i][j]
                      if j != 4:
                         empstr = empstr + ", "
                         j += 1
                         if i+1 != int(empcount):
                            empstr = empstr + "\n"
                            j = 0
                            i += 1
                           print(empstr)
                           print[employees]
                        elif programselection < 3:
                           empmangpro = False
                        else:
                             print("Please enter valid information")
                except ValueError:
                print("Please enter valid information")
                continue
然后在主文件中:

class Employee:
    def __init__(self, name): # can add all you need social security, ...
        first, last = name.split(' ')
        self.first = first # add a new line per new parameter
        self.last = last
    def __str__(self):
        # here you can add all of your logic
        # to properly format social security, phone number, etc.
        # just be sure to return a string, and not print a string!
        return f'{self.last}, {self.first}'
输出:

import employee # put at top of file
employees = [Employee('John Doe'), Employee('Jane Doe')] # sample data
for e in employees:
    print(e)
至于间隔不正确:

Doe, John
Doe, Jane
以及:


不太清楚您在选项2中试图做什么。以后尝试注释代码。你帖子中的标签不准确,所以我做了一些猜测。也许这会帮助你解决你的问题:

            except ValueError:
                print("Please enter valid information")
                continue
empmangpro=True
雇员=[]
当empmangpro==True时:
尝试:
empcount=len(员工)
打印(“--------------员工管理系统------------------”)
打印(“”)
打印(“系统中有”+str(empcount)+“员工”)
打印(“”)
打印(“---------------------------------------------------------------------------”)
打印(“1.添加新员工”)
打印(“2.查看所有员工”)
programselection=int(输入(“请选择您的选项号:”)
如果programselection==1:
雇员=[]
append(输入(“名字和姓氏:”)
employee.append(输入(“社会安全号:”)
employee.append(输入(“电话号码:”)
employee.append(输入(“电子邮件地址:”)
employee.append(输入(“工资:$”)
employees.append(雇员)
elif programselection==2:
i=0
j=0
empstr=“”
当我数的时候:
打印(str(员工[i])+“\n”)
i+=1
elif程序选择>2:
empmangpro=False
打印(“停止程序”)
其他:
打印(“请输入有效信息”)
除值错误外:
打印(“请输入有效信息”)
持续

另外,如果要停止程序,请在
程序选择==1:
后使用
elif programselection>2:
而不是
elif programselection<3:

?现在看来并非如此。另外,
elif
应该与
if
处于同一级别。我在发布此内容时弄乱了间距,我没有收到任何错误或任何东西,只是当我选择选项2时,什么都没有发生,只是空白。您要求我们用python之类的语言调试间距不正确的代码,这样它可以改变程序控制。我们如何知道它是在哪里复制的意大利面或它是真正的问题(隐藏)。嘿@Corey如果我被认为是粗鲁的话,很抱歉。我想帮助你,并要求你努力正确格式化你的代码块。没关系,我想我现在得到了正确的间距?
            except ValueError:
                print("Please enter valid information")
                continue
empmangpro = True
employees = []
while empmangpro == True:
    try:
        empcount = len(employees)
        print("--------------------Employee Management System--------------------")
        print("")
        print("There are "+str(empcount)+" employees in the system.")
        print("")
        print("------------------------------------------------------------------")

        print("1. Add new employee")
        print("2. View all employees")
        programselection = int(input("Please select your option number: "))

        if programselection == 1:
            employee = []
            employee.append(input("First and Last Name: "))
            employee.append(input("Soci1al Security Number: "))
            employee.append(input("Phone Number: "))
            employee.append(input("Email Address: "))
            employee.append(input("Salary:$"))
            employees.append(employee)
        elif programselection == 2:
            i = 0
            j = 0
            empstr = ""
            while i < empcount:
                print(str(employees[i])+"\n")
                i += 1

        elif programselection > 2:
            empmangpro = False
            print("Stopping programm")
        else:
            print("Please enter valid information")
    except ValueError:
        print("Please enter valid information")
        continue