Answer:
def makeStudent(student_list):
    name = input()
    major = input()
    year = int(input())
    hhh = int(input())
    gpa = float(input())
    newstu = Student(name,major,year,hhh,gpa)
    student_list.append(newstu)
def setGPA(student,val):
    student = student._replace(gpa= val)
    return student
def setMajor(student,val):
    student = student._replace(major = val)
    return student
def setYear(student,val):
    student = student._replace(year = val)
    return student
def averageGPA(student_list):
    sum = 0
    for i in range(len(student_list)):
        sum = sum + student_list[i].gpa
    avg = sum/len(student_list)
    return avg
def getTopStudentGPA(student_list):
    max = -1000
    for i in range(len(student_list)):
        if student_list[i].gpa > max:
            max = student_list[i].gpa
    return max
Student = namedtuple('Student', ['name', 'major', 'year', 'id', 'gpa'])
stu1 = Student('Kenneth', 'Computer Science', 6, 987654321, 3.8)
stu2 = Student('Maegan', 'Neuroscience', 4, 123456789, 3.4)
namedlist = []
print (namedlist)
namedlist.append(stu1)
namedlist.append(stu2)
print(namedlist)
makeStudent(namedlist)
makeStudent(namedlist)
makeStudent(namedlist)
print(namedlist)
print(namedlist[1])
print(namedlist[3])
Explanation:
- Create a function to take in in the information of a new student.
- Create functions for setting GPA, a major subject and year.
- Calculate average GPA by dividing the total GPA of student with the length of student list.
- Get top student by checking the student having a maximum GPA
.