Python Forum

Full Version: Name Error: OO programming
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have coded this example from a course textbook (it says it is a working example), When I run the code, it is coming with a Name Error, Assessment not defined.

I have played around with the code but with no luck. Can anyone please help me correct the error? (I have followed the book line by line).

class Course:
    def __init__(self,t,m):
        
        self.__CourseTitle=t
        self.__MaxStudents=m
        self.__NumberOfLessons=0
        self.__CourseLesson=[]
        self.__CourseAssessment=Assessment


    def AddAssessment(self,t,m):
        self.__CourseAssessment=Assessment(t,m)

    def AddLesson(self,t,d,r):
        self.__NumberOfLessons=self.__NumberOfLessons+1
        self.__CourseLesson.append(Lesson(t,d,r))

    
        
    def OutputCourseDetails(self):
        print(self.__CourseTitle,"Maximum Number: ",self.__MaxStudents)
        for i in range(self.__NumberOfLessons):
            print(self.__CourseLesson[i].OutputLessonDetails())

    
MyCourse=Course("Computing",10)

MyCourse.AddAssessment("Programming",100)
MyCourse.AddLesson("Problem Solving",60,False)
MyCourse.AddLesson("Programming",120,True)
MyCourse.AddLesson("Theory",60,False)



MyCourse.OutputCourseDetails()
Your code has not defined Assessment neither has it defined Lesson look in the course textbook for where thse are defined and add them to your code.
I realized my mistake, I had to create the Assessment and Lesson classes which was an additional task.

thank you!