Question
from collections import namedtuple Student = namedtuple('Student', ['name', 'major', 'year', 'id', 'gpa']) stu1 = Student('Kenneth', 'Computer Science', 6, 987654321, 3.8) stu2 = Student('Maegan', 'Neuroscience', 4,
from collections import namedtuple 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 = [] namedlist.append(stu1) namedlist.append(stu2)
def makeStudent(student_list): """Make student.""" name = input() major = input() year = int(input()) hhh = int(input()) gpa = float(input()) newstu = Student(name, major, year, hhh, gpa) student_list.append(newstu) makeStudent(namedlist) makeStudent(namedlist) makeStudent(namedlist) print(namedlist) print(namedlist[1]) print(namedlist[3]) This is the code in 3.21:
Please help using Python!
3.22 ZyLab: NamedTuples 3 - Complete Now that we have a list of Students we're going to make some functions that will allow us to update the student's information and get some stats about them. 1. Copy ALL Functional (3.21) code within the provided template and retain any print statements. Pay attention to the comments when copying and pasting since you will be reorganizing your code based on the template. 2. Create the following functions: set GPA( student, val): student is a single Student namedtuple, val is a float. The function sets the student's gpa = val and returns the student setMajor (student, val): Same as setGPA except val is a string. The function sets the student's major = val and returns the student set Year (student, val): Same as setMajor except val is an int. The function sets the student's year = val and returns the student averageGPA (student_list): student_list is the list of Student namedtuples. The function returns the average gpa of the students. get TopStudent GPA( student_list): student_list is the list of Student namedtuples. The function returns the highest gpa of the students in student_list. 3. Print out what the average gpa of the students are and then print out the top student's gpa. 4. Maegan's information needs to be updated. Do the following: Change Maegan's gpa to 4.0 Change Maegan's major to 'Computational Neuroscience' Change Maegan's year to 5 5. Repeat 3. HINT: for the set GPA, setMajor, and set Year functions you will need to use the x_replace) method as follows: student = student._replace(gpa = val) 5. Repeat 3. HINT: for the set GPA, set Major, and set Year functions you will need to use the x._replace() method as follows: student = student. _replace(gpa = val) HINT: For functions averageGPA and getTopStudent GPA, assume that there will only be 5 students in student_list LAB ACTIVITY 3.22.1: ZyLab: Named Tuples 3 - Complete 0/10 main.py Load default template... 1 from collections import namedtuple AWN 3 Student = namedtuple('Student', ['name', 'major', 'year', 'id', 'gpa']) Ovo def makeStudent(student_list): ""Make student." name = input major = input year = int(input) hhh = int(input) gpa - float(input) newstu - Student(name, major, year, hhh, gpa) student_list.append(newstu) 11 17 def setGPA student, val): ""Student." Develop mode Submit mode Run your program as often as you'd like, before submitting for grading. Below, type any needed input values in the first box, then click Run program and observe the program's output in the second box Enter program input (optional) If your code requires input values, provide them here. Run program Input (from above) main.py (Your program) Output (shown below) Program output displayed hereStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started