Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Question about NameError
#1
Hi, I am learning Python object oriented programming through this Youtube video. I am following along with his code. However, I am getting a "NameError" where I cannot pin-point where my error is in my code. I triple checked word-for-word of my code with the Youtuber's code and it matches up, but I am not sure why I am getting an error and he is not. Any help or suggestions would be greatly appreciated. Thanks!

class Student:
    def __init__(self, name, age, grade):
        self.name = name 
        self.age = age
        self.grade = grade
    
    def get_grade(self):
        return self.grade

class Course:
    def __init__(self, name, max_students):
        self.name = name
        self.max_students = max_students
        self.students = []

    def add_student(self, student):
        if len(self.students) < self.max_students:
            self.students.append(student)
            return True
        return False
    
    def get_average_grade(self):
        pass

s1 = Student("Tim", 19, 95)
s2 = Student("Bill", 19, 75)
s3 = student("Jill", 19, 65)

course = Course("science", 2)
course.add_student(s1)
course.add_student(s2)
print(course.students)
Reply


Messages In This Thread
Question about NameError - by Than999 - Dec-10-2021, 03:08 PM
RE: Question about NameError - by Larz60+ - Dec-10-2021, 03:53 PM
RE: Question about NameError - by Than999 - Dec-10-2021, 03:54 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Beginner question NameError amazing_python 6 2,669 Aug-13-2021, 07:28 AM
Last Post: amazing_python
  NameError: NameError: global name 'BPLInstruction' is not defined colt 7 4,593 Oct-27-2019, 07:49 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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