Question: My code so far: import csv # Create a class named Student # This class is used to store the student details in the form

My code so far:
import csv
# Create a class named Student
# This class is used to store the student details in the form of object
class Student:
def __init__(self, student_id, last_name, first_name, major, disciplinary_action=False):
self.student_id = student_id
self.last_name = last_name
self.first_name = first_name
self.major = major
self.disciplinary_action = disciplinary_action
self.gpa = None
self.graduation_date = None
def set_gpa(self, gpa):
self.gpa = gpa
def set_graduation_date(self, graduation_date):
self.graduation_date = graduation_date
# Read the Students Majors List file
def read_student_majors(filename):
students ={}
with open(filename, mode="r", newline="") as file:
reader = csv.reader(file)
for row in reader:
student_id, last_name, first_name, major, disciplinary_action = row
disciplinary_action = True if disciplinary_action.upper()=='Y' else False
students[student_id]= Student(student_id, last_name, first_name, major, disciplinary_action)
return students
# Read the GPAList file
def read_gpa(filename, students):
with open(filename, mode="r", newline="") as file:
reader = csv.reader(file)
for row in reader:
student_id, gpa = row
if student_id in students:
students[student_id].set_gpa(float(gpa))
# Read the Graduation Dates List file
def read_graduation_dates(filename, students):
with open(filename, mode="r", newline="") as file:
reader = csv.reader(file)
for row in reader:
student_id, graduation_date = row
if student_id in students:
students[student_id].set_graduation_date(graduation_date)
# a
def sort_by_last_name(student):
return student.last_name
# Create a function named generate_full_roster () to generate the complete student information sorted alphabetically by student last name.
def generate_full_roster(students):
# Sort students dictionary values alphabetically by last name
sorted_students = sorted(students.values(), key=sort_by_last_name)
# Write data to FullRoster.csv
with open("FullRoster.csv", mode="w", newline="") as file:
writer = csv.writer(file)
# Write header
writer.writerow(
["student_id", "major", "first_name", "last_name", "GPA", "graduation_date", "disciplinary_action"])
# Write student data
for student in sorted_students:
writer.writerow([student.student_id, student.major, student.first_name, student.last_name, student.gpa,
student.graduation_date, "Y" if student.disciplinary_action else "N"])
# b
def sort_by_student_id(student):
return student.student_id
# Create a function named generate_major_lists () to generate the student information sorted by student id.
def generate_major_lists(students):
# Create separate CSV files for each major
for major in set(student.major for student in students.values()):
# Remove spaces in major name for the file name
filename = f"{major.replace('','')}Students.csv"
# Filter students by major
major_students =[student for student in students.values() if student.major == major]
# Sort students by their student ID
major_students.sort(key=sort_by_student_id)
# Write data to CSV file
with open(filename, mode="w", newline="") as file:
writer = csv.writer(file)
# Write header
writer.writerow(["student_id", "last_name", "first_name", "graduation_date", "disciplinary_action"])
# Write student data
for student in major_students:
writer.writerow([student.student_id, student.last_name, student.first_name, student.graduation_date,
"Y" if student.disciplinary_action else "N"])
# c.
def sort_by_gpa(student):
return student.gpa
# Create a function named generate_scholarship_candidates () to generate the student information sorted by gpa.
def generate_scholarship_candidates(students):
# Filter eligible students with GPAs >3.8 who haven't graduated or had disciplinary action taken
eligible_students =[student for student in students.values() if
student.gpa >3.8 and not student.disciplinary_action]
# Sort eligible students by GPA from highest to lowest
eligible_students.sort(key=sort_by_gpa, reverse=True)
# Write data to ScholarshipCandidates.csv
with open("ScholarshipCandidates.csv", mode="w", newline="") as file:
writer = csv.writer(file)
# Write header
writer.writerow(["student_id", "last_name", "first_name", "major", "GPA"])
# Write student data
for student in eligible_students:
writer.writerow([student.student_id, student.l
My code so far: import csv # Create a class named

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!