I am really new to Python but learning quickly. I know what I want to accomplish, just not sure how to phrase the question or terminology.
I'm wanting to add a unique student to each classroom, if I add an existing student name, I expect the add_student function to not add the student to the class.
class Student:
def __init__(self, student_name):
self.name: str = student_name
self.age: int = 0
self.gender: str = ''
class Classroom:
def __init__(self, classroom_name):
self.classroom_name: str = classroom_name
self.teacher_name: str = ''
self.student_list: Student = []
def add_student(self, student_name):
if student_name not in self.student_list:
self.student_list.append(student_name)
def remove_student(self, student_name):
if student_name in self.student_list:
self.student_list.remove(student_name)
def list_student(self):
for s in self.student_list:
print(s.name)
classroom = Classroom('Science')
std1 = Student('Joe')
std2 = Student('Joe')
std3 = Student('Joe')
classroom.add_student(std1)
classroom.add_student(std2)
classroom.add_student(std3)
classroom.list_student()