After the feedback I got on my previous question, I decided to try one more program to see if I understand O.O.P. The idea for this is also based off the project I am working on im my class for this semester which is to make an interactive school tour.
This program just has you make a bunch of teacher instances and then prints them all out.
class Teacher:
def __init__(self, name, subject, room_number):
self.name = name
self.subject = subject
self.room_number = room_number
def print_info(self):
return self.name, self.subject, self.room_number
def instagator(teachers: list) -> list:
"""Creates a version of the teacher class"""
print("")
name = input("Please enter a teachers name: ")
subject = input("Please enter that teachers subject: ")
room_number = input("Please enter what room that teacher teaches in: ")
# Makes the varible that holds the instance names after the teacher
globals()[name] = Teacher(name, subject, room_number)
teachers.append(globals()[name])
return teachers
teachers = []
print("Please enter the name of 10 teachers, the subject they teach, and the room they teach that subject in.")
for _ in range(10):
teachers = instagator(teachers)
print("\n")
for teacher in teachers:
info = teacher.print_info()
print(f"{info[0].capitalize()} teaches {info[1]} in room {info[2]}. \n")
As with before I just want to know if there is anything wrong with my approach to O.O.P. as I still have very little idea of what I am doing.