Я получаю ошибку AttributeError: у объекта 'str' нет атрибута 'courseGrade', и я не знаю, как продолжить. Я не уверен, как я создал ошибку атрибута. Тем не менее, я не часто использую Python.
class course:
def __init__(self, courseName, courseNumber, courseGrade):
self.courseName = courseName
self.courseNumber = courseNumber
self.courseGrade = courseGrade
#%%
# student class. Tracks student name and cumulative GPA
# default GPA is 0 unless passed in for a transfer student
# courses will be a list of courses the student takes
class student:
def __init__(self,firstName,lastName, cumulativeGPA = 0):
self.firstName = firstName
self.lastName = lastName
self.cumulativeGPA = cumulativeGPA
self.courses = []
# method to add courses to the student transript
def enterGrade(self, courseNumber, courseName, courseGrade):
newCourse = (courseName, courseNumber, courseGrade)
self.courses = newCourse
self.cumulativeGPA = self._updateGPA(courseGrade)
# private method to maintain the student GPA
def _updateGPA(self,newGrade):
totalGPA = 0
for x in self.courses:
totalGPA += totalGPA + x.courseGrade
numCourses += 1
self.cumulativeGPA += round(totalGPA//numCourses,2)
# method to print the student transcript.
def printTranscript(self):
print(self.lastName, ' ', self.firstName, ' GPA
',self.cumulativeGPA)
for x in self.courses:
print(' ', x.courseNumber, ' ', x.courseName, ' ',
x.courseGrade)