Python 7 Levels, L4, Unit 36, Student Performance Management System, II

Powered By EmbedPress

Exercise:

student_all = []#2 dimentional list, each item in the list is a student
while True:
    number = input("Please input an operation:\n"\
                   "1.Add Student\n2.Search Student\n3.Delete Student\n4.Update Student\n5.View All Student\n99.Quit\n")
    if number == "99":
        print("Abort system.")
        break
    elif number == "1":
        student = []#information list for one student, store all the student information
        name = input("Please input student name:")
        age = int(input("Please input student age:"))
        chinese = 0
        math = 0
        english = 0
        sum_score = 0
        avg_score = 0
        student.append(name)
        student.append(age)
        student.append(chinese)
        student.append(math)
        student.append(english)
        student.append(sum_score)
        student.append(avg_score)
        student_all.append(student)#add the student information to student list

        print("Name\tAge\tFrench\tMath\tEnglish\tTotal Score\tAverage Score")
        for i in student:
            print(i,end = "   \t" )
        print()#output new line

    elif number == "2":
        name = input("Please input student name you look for:")
        for i in range(len(student_all)):
            if name in student_all[i]:
                print("Name\tAge\tFrench\tMath\tEnglish\tTotal Score\tAverage Score")
                for j in student_all[i]:
                    print(j,end = "   \t")
                print()#output a new line
                break
        else:
            print(name," does not exist.")

    elif number == "3":
        name = input("Please input the student name to be deleted: ")
        for i in range(len(student_all)):
            if name in student_all[i]:
                del student_all[i]
                print(name," has been deleted.")
                break
        else:
            print(name," does not exist")

    elif number == "4":
        name = input("Please input student name to be updated:")
        for i in range(len(student_all)):
            if name in student_all[i]:
                name = input("Please input the updated name:")
                age = int(input("Please input the updated age:"))
                student_all[i][0] = name
                student_all[i][1] = age
                print("Update succeeds.")
                print("Name\tAge\tFrench\tMath\tEnglish\tTotal Score\tAverage Score")
                for j in student_all[i]:
                    print(j,end = "   \t")
                print()#output a new line
                break
        else:
            print(name," does not exist.")

    elif number == "5":
        print("Name\tAge\tFrench\tMath\tEnglish\tTotal Score\tAverage Score")
        for i in range(len(student_all)):
            for j in range(len(student_all[i])):
                print(student_all[i][j],end = "   \t")
            print()#output a new line

dahan1999

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts