让搜索返回不显示一个员工的全部信息。然后可以编辑该员工的信息

时间:2019-09-16 18:52:08

标签: python

创建一种功能,该功能利用循环和字符串解析来搜索列表中的所有员工,并仅返回SSN与用于搜索的SSN相匹配的员工的信息。搜索员工信息后,便可以对其进行编辑。

with rails_env: 'staging' do
  execute :rake, 'release:rollback_staging' if rake_exists? 'release:rollback_staging'
end

我已经按照必要的格式返回了搜索结果,但它显示了所有员工,而不仅仅是我需要的一位员工。

1 个答案:

答案 0 :(得分:0)

在您的searchEmployee函数中,您需要添加一个条件来检查员工的SSN是否与用户提供的SSN相匹配:

#Search for employee by SSN
def searchEmployee():
    cls()
    print("--------------- Search for Employee by SSN ---------------\n")
    try:
         if (len(lstEmployee)==0):
            #when no employees in the system, view the "No employee in the list" message
            print("-------------------------------------------------------------------")
            print("               No employees in the list.")
            print("-------------------------------------------------------------------")
        else:
            #display searched employee
            search=int(input("Please enter the SSN of the Employee you wish to search: "))
            cls()
            for currentEmployee in lstEmployee:
                if currentEmployee.ssn == search:
                    # TODO: print employee info
                    break
            else
                print("-------------------------------------------------------------------")
                print("               Employee with the given SSN not found.")
                print("-------------------------------------------------------------------")
            try:
                option=int(input('Enter 0 to exit to menu or any key to continue to edit this information: '))
                if option == 0:
                    cls()
            except:
                cls()
    except ValueError:
        print("SSN does not match any employee")
        return searchEmployee()