Answer the question
In order to leave comments, you need to log in
How to get information from a class object through a dictionary?
class Student
class Student:
id = ''
name = ''
group = ''
average_score = ''
def __init__(self, _id, _name, _group, _average_score):
self.id = _id
self.name = _name
self.group = _group
self.average_score = _average_score
class StudentsSystem:
Handler = {}
def __init__(self):
print("Ready to work with students' data")
def AddStudent(self, _id, _name, _group, _avgscore):
self.Handler[_id] = Student(str(_id), str(_name), str(_group), str(_avgscore))
def PrintInformation(self, _id):
try:
print(self.Handler[_id])
except KeyError:
print("Wrong child's ID")
studentModule = StudentsSystem() # MAIN OBJECT
studentModule.AddStudent("321234312232", "Roh Socko", "9-A", "3.5")
studentModule.PrintInformation("321234312232") # GET STUDENT'S INFORMATION USING ID
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question