Question: Python 3.7+. Can somebody fix this code so that the testing code runs? I'm getting this error: __init__() got an unexpected keyword argument 'status'. I've
Python 3.7+. Can somebody fix this code so that the testing code runs? I'm getting this error: "__init__() got an unexpected keyword argument 'status'". I've provided the code and the testing code at the bottom (Under the comment that says "Test").
class Student:
totalEnrollment=0
def __init__(self, name, major='IST',enrolled='y',credits=0,qpoints=0):
Student.totalEnrollment+=1
self.name=name
self.major=major
self.enrolled=enrolled
self.credits=credits
self.qpoints=qpoints
self.g_num="G0000"+str(Student.totalEnrollment)
def gpa(self):
try:
return self.qpoints/self.credits
except ZeroDivisionError :
return 0
def __str__(self):
return self.name+", "+self.g_num+", "+self.status()+", "+\
self.major+", active: "+self.enrolled+" , credits = "+\
str(self.credits)+", "+'%.2f' % self.gpa()
def isEnrolled(self):
if self.enrolled == 'y':
return True
elif self.enrolled == 'n':
return False
else:
pass
def status(self):
if self.credits <= 30:
return "Freshman"
elif self.credits > 30 and self.credits <=59:
return "Sophomore"
elif self.credits >=60 and self.credits <=89:
return "Junior"
elif self.credits >=90:
return "Senior"
else:
pass
def sameStudent(self,other):
if self.g_num == other.g_num:
return True
else:
return False
def setMajor(self, major):
''' Change the student's major to new value.'''
self.major = major
class Department:
univ_students = 0
def __init__(self, d_code, d_name, capacity, minGPA):
self.d_code = d_code
self.d_name = d_name
self.capacity = capacity
self.minGPA = minGPA
self.num_students = 0
self.avgGPA = 0
self.roster = []
def addStudent(self, student):
qualifed, reason = self.isQualified(student)
if not qualifed:
return qualifed, reason
self.roster.append(student)
self.avgGPA = ((self.avgGPA * self.num_students) + student.gpa()) / (self.num_students() + 1)
student.setMajor(self.d_name)
self.num_students += 1
return True, 'Added'
def isQualified(self, student):
if self.num_students == self.capacity:
return False, 'Over capacity.'
elif student.gpa() < self.minGPA:
return False, 'Student has lower GPA than required.'
elif student in self.roster:
return False, 'Student already in roster.'
elif student.enrolled == 'n':
return False, 'Student is not yet enrolled.'
else:
return True, 'Student is qualified.'
def __str__(self):
return self.d_code + ", " + self.d_name + ", " + self.capacity + ", " + self.minGPA + ", " + self.num_students + ", " + self.avgGPA
def printRoster(self):
print('g_num\tname')
for s in self.roster:
print(f'{s.g_num}\t{s.name}')
#Test
print(' Start of Department and Student class demo **************')
s1 = Student('G34568', 'David Miller', status = 'sophomore', major = 'Hist', enrolled = 'y', credits = 30, qpoints = 90) s2 = Student('G21345', 'Sonia Fillmore', status = 'senior', major = 'Math', enrolled = 'y', credits = 90, qpoints = 315) s3 = Student('G42156', 'Chris Squire', status = 'sophomore', major = 'Musc', enrolled = 'y', credits = 45, qpoints = 160) s4 = Student('G10928', 'Tal wilkenfeld', status = 'junior', major = 'ARTS', enrolled = 'y', credits = 70, qpoints = 225) s5 = Student('G22157', 'Larry Graham', status = 'senior', major = 'CHHS', enrolled = 'y', credits = 105, qpoints = 290) s6 = Student('G31345', 'John Entwistle', status = 'freshman', major = 'CSci', enrolled = 'y', credits = 15, qpoints = 35) s7 = Student('G44568', 'Esperanza Spalding', status = 'junior', major = 'ENGR', enrolled = 'y', credits = 65, qpoints = 250) s8 = Student('G55345', 'Tim Bogert', status = 'sophomore', major = 'Hist', enrolled = 'y', credits = 45, qpoints = 120) s9 = Student('G66113', 'Gordon Sumner', status = 'freshman', major = 'Musc', enrolled = 'y', credits = 15, qpoints = 45) s10 = Student('G11311', 'Paul McCartney', status = 'senior', major = 'ARTS', enrolled = 'y', credits = 110, qpoints = 275) s11 = Student('G22111', 'Elizabeth Smythe', status = 'junior', major = 'ENGR', enrolled = 'y', credits = 85, qpoints = 250) s12 = Student('G31312', 'John McVie', status = 'sophomore', major = 'Hist', enrolled = 'y', credits = 45, qpoints = 120) s13 = Student('G31312', 'Nawt Enrolled', status = 'sophomore', major = 'Hist', enrolled = 'n', credits = 45, qpoints = 120) s14 = Student('G11112', 'Toolow G. Peyay', status = 'freshman', major = 'Undc', enrolled = 'y', credits = 20, qpoints = 38)
print('List of Students created: ') print('s1= ',s1) print('s2= ',s2) print('s3= ',s3) print('s4= ',s4) print('s5= ',s5) print('s6= ',s6) print('s7= ',s7) print('s8= ',s8) print('s9= ', s9) print('s10= ',s10) print('s11= ',s11) print('s12= ',s12) print('s13= ',s13) print('s14= ',s14) d1 = Department('ENGR', 'Engineering', 5, 2.75) d2 = Department('ARTS', 'Art and Architecture', 15, 2.0) d3 = Department('CHHS', 'College of Health and Human Sevrices', 10, 2.5) print(' Departments established:') print(d1) print(d2) print(d3) print(' Adding s1 - s5 to ENGR Department- print Roster follows') d1.addStudent(s1) d1.addStudent(s2) d1.addStudent(s3) d1.addStudent(s4) d1.addStudent(s5) d1.printRoster()
a, b = d1.addStudent(s6) print(' Attempting to add ', s6.name, ' to ', d1.d_code, ' - over capacity, ret values: ', a, b) d1.printRoster() print(' Adding ', s6.name, ' and ', s7.name, ' to ', d2.d_code, ', printRoster follows: ') d2.addStudent(s6) d2.addStudent(s7) d2.printRoster()
print(' Adding ', s8.name, ' and ', s9.name, ' to ', d3.d_code, ', printRoster follows: ') d3.addStudent(s8) a, b = d3.addStudent(s9) print(' Attempting to add qualified student , ', s9.name, ' to ', d3.d_code, ', CHHS, return values; ', a, b) d3.printRoster()
a, b = d3.addStudent(s14) print(' Attempting to add low GPA student ', s14.name, ', return values: ', a, b)
a, b = d2.addStudent(s13) print(' Attempting to add non-enrolled student ', s13.name, ', return values: ', a, b)
a, b = d3.addStudent(s8) print(' Attempting to add dupe student ', s8.name, ', return values: ', a, b)
print(' Adding s10 to ENGR, s11 to ARTS, s12 to CHHS, then print all 3 roster') d1.addStudent(s10) d2.addStudent(s11) d3.addStudent(s12)
d1.printRoster() d2.printRoster() d3.printRoster() print(' ***** End **********')
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
