程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了需要有关python以某种方式显示信息的帮助大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决需要有关python以某种方式显示信息的帮助?

开发过程中遇到需要有关python以某种方式显示信息的帮助的问题如何解决?下面主要结合日常开发的经验,给出你关于需要有关python以某种方式显示信息的帮助的解决方法建议,希望对你解决需要有关python以某种方式显示信息的帮助有所启发或帮助;
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" )
        print( "3. Search employee by SSN" )
        print( "4. Edit employee information" )
        programSELEction = int( input( "Please SELEct your option number: " ) )

        if programSELEction == 1:
            employee = []
            while True:
                try:
                    print( "-----------------------------------------------------------------" )
                    print( "                    employee information" )
                    print( "" )
                    print( "-----------------------------------------------------------------" )
                    print( "" )
                    name = input( "employee First and last name: " )
                    ssn = input( "Social Security number: " )
                    phone = input( "Phone number: " )
                    email = input( "Email: " )
                    salary = input( "Salary: $" )
                    print( "" )
                    print( "" )
                    print( "---------------------- {0:s} ----------------------------".format( name ) )
                    print( "Social Security #: {0:s}".format( ssn ) )
                    print( "Phone number: {0:s}".format( phone ) )
                    print( "Email Address: {0:s}".format( email ) )
                    print( "Salary: ${0:s}".format( salary ) )
                    print( "---------------------------------------------------------------" )
                    print( "" )
                    employee.append( name )
                    employee.append( ssn )
                    employee.append( phone )
                    employee.append( email )
                    employee.append( salary )
                    employees.append( employee )
                    break
                except ValueError:
                    print( "Please Enter ValID information." )
                    conTinue
        elif programSELEction == 2:
            i = 0
            empstr = ""
            while i < len(employees):
                empstr = empstr + "------------------ " + employees[i][0] + " ------------------------" + "\n"
                empstr = empstr + "SSN: " + employees[i][1] + "\n"
                empstr = empstr + "Phone: " + employees[i][2] + "\n"
                empstr = empstr + "Email: " + employees[i][3] + "\n"
                empstr = empstr + "Salary: $" + employees[i][4] + "\n"
                empstr = empstr + "-----------------------------------------------------" + "\n"
                i += 1
            print(empstr)
            print("\n")
        elif programSELEction == 3:
            ssnSearch = input("Enter SSN to search by:")
            i = 0
            j = 0
            k = 0
            empstr = ""
            while i < int(empcount):
                while j < 5:
                    if employees[i][j] == ssnSearch:
                        while k < 5:
                            empstr = empstr + employees[i][k]
                            if k != 4:
                                empstr = empstr + ",\n"
                            k += 1
                    j += 1
                j = 0
                i += 1
            print(empstr)
    except ValueError:
        print("Please enter valID information")
        conTinue

我如何将programSELEction == 3 显示为programSELEction == 2?

解决方法

您可以定义一个函数并调用它来打印值。

def print_empInfo(emp):
    print( "" )
    print( "" )
    print( "---------------------- {0:s} ----------------------------".format( emp[0]) )
    print( "Social Security #: {0:s}".format( emp[1]) )
    print( "Phone number: {0:s}".format( emp[2] ) )
    print( "Email Address: {0:s}".format( emp[3] ) )
    print( "Salary: ${0:s}".format( emp[4] ) )
    print( "---------------------------------------------------------------" )
    print( "" )

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" )
        print( "3. Search employee by SSN" )
        print( "4. Edit employee information" )
        programSELEction = int( input( "Please SELEct your option number: " ) )

        if programSELEction == 1:
            employee = []
            while True:
                try:
                    print( "-----------------------------------------------------------------" )
                    print( "                    employee information" )
                    print( "" )
                    print( "-----------------------------------------------------------------" )
                    print( "" )
                    name = input( "employee First and last name: " )
                    ssn = input( "Social Security number: " )
                    phone = input( "Phone number: " )
                    email = input( "Email: " )
                    salary = input( "Salary: $" )
                    
                    employee.append( name )
                    employee.append( ssn )
                    employee.append( phone )
                    employee.append( email )
                    employee.append( salary )
                    employees.append( employee )
                    
                    print_empInfo(employeE)
                    
                    break
                except ValueError:
                    print( "Please Enter Valid Information." )
                    conTinue
        elif programSELEction == 2:
            i = 0
            while i < empcount:
                print_empInfo(employees[i]) #pass each employee info to print
                i += 1
        elif programSELEction == 3:
            ssnSearch = input("Enter SSN to search by:")
            i = 0
            while i < empcount:
                if employees[i][1] == ssnSearch:  #ssn is the 2nd element for each emp. check explicitly
                    print_empInfo(employees[i]) #pass the found employee to print
                    break #once printed,exit the loop
                i += 1
            print ('employee not found') #if it went thru full loop,emp was not found

    except ValueError:
        print("Please enter valid information")
        conTinue

大佬总结

以上是大佬教程为你收集整理的需要有关python以某种方式显示信息的帮助全部内容,希望文章能够帮你解决需要有关python以某种方式显示信息的帮助所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: