need help in python code
Anonymous in /c/coding_help
923
report
hello, i am beginner in python and i just learn classes in python and i were trying to make a program that have student class and college class and college have list of students and i need to add student in college and print them out. what i am trying to say you can see in below code<br><br>```<br>class student:<br> def __init__(self, name, roll_number) -> None:<br> self.name = name<br> self.roll_number = roll_number<br><br>class colledge:<br> def __init__(self, colledge_name, departments):<br> self.colledge_name = colledge_name<br> self.departments = departments<br><br>class add_student(colledge):<br> def add(self, students): <br> self.students = students<br><br> def print_details(self):<br> for i in self.students:<br> print(f"{i.name} {i.roll_number}")<br><br>#main function<br><br>student1 = student("fahad", 343)<br>student2 = student("fahim", 324)<br>student3 = student("kamran", 3244)<br><br>colledge1 = add_student("szabist", "cs")<br><br>colledge1.add([student1, student2, student3])<br>colledge1.print_details()<br>```<br><br> so first question is that is my code is right or wrong or need some correction and what are some rules and regulations need to follow while making program with classes <br><br>2nd thing is that should i use setter and getter in my code as beginner or not or if yes then how and where i use them in this code. <br><br>i am waiting for you kind response
Comments (16) 29238 👁️