Python Forum
Name Error: OO programming
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Name Error: OO programming
#1
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()
Reply
#2
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.
Reply
#3
I realized my mistake, I had to create the Assessment and Lesson classes which was an additional task.

thank you!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Verilog HDL Programming to Python Programming? noobcoder 1 3,035 Jul-18-2019, 09:28 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020