pls can anybody show how works printing? here is the code:

class Student(object):
    def __init__(self, name):
        self.name = name
        self.report = dict()

    def add_subject(self, subject):
        self.report[subject] = list()

    def subjects(self):
        return self.report.keys()

    def s_subjects(self):
        for subject in self.subjects():
        print lpre

class Subject(object):
    def __init__(self, name, teacher = "unknown"):
        self.name = name
        self.teacher = teacher

def main():
    janko = Student('Janko Moor')
    janka = Student ('Janka Vaskova')

    fyz = Subject('fyzic')
    eng = Subject('english')
    mat = Subject('matematic')
    hist= Subject('history')
    bio = Subject('biology')


    print janko.s_subjects()

if __name__ == '__main__':

I just need to know the principe how to print the subjects of the student (janko). I am a bit struggling because it always shows me "objects" of all subjects. I need to see it like: matematic, fyzic,...etc. I really donĀ“t know what I need to add to the code to make it appropriate. Pls can you show me?

Replace line 18 with lpre.append(subject.name) . You can also replace line 19 with return ", ".join(lpre) .

Edited 4 Years Ago by Gribouillis: n/a

This question has already been answered. Start a new discussion instead.