Hello,
I am learning classes, and find it a bit difficult... :-(
Mine intention is to add subject(predmet) and mark to the objet janko but
if I search in self.predmety, I get False, means that it can't
recognise predmet in self.predmety list
State of self.predmety is as folloving:
[<__main__.Cpredmet instance at 0x010F5260>, <__main__.Cpredmet instance at 0x010F5210>, <__main__.Cpredmet instance at 0x010F5238>]
I presume that it can not recognize predmet (subject) in that state... Pls I need advice how to find a predmet in self.predmety list.
I approciate your help!
class Cstudent():
def __init__(self, name):
self.name = name
self.predmety = []
self.mark = []
self.absence = 0
def add_subject(self, predmet):
'''
@param predmet: objekt typu predmet
'''
self.predmety.append(predmet)
def add_mark(self, predmet, mark):
if predmet in self.predmety:
print True
else:
print False
def print_zoznam_predmetov(self):
return self.predmety
class Cpredmet():
def __init__(self, nazov):
self.nazov = nazov
self.znamky = []
def add_znamka(self, znamka):
self.znamky.append(znamka)
def average_predmet(self, predmet):
return sum(self.znamky) / len(self.znamky)
def main():
janko = Cstudent('janko mrkvicka')
fyz = Cpredmet('fyzika')
eng = Cpredmet('english')
janko.add_subject(Cpredmet('matematika'))
janko.add_subject(fyz)
janko.add_subject(eng)
janko.add_mark(predmet='fyzika', mark=4)
print janko.print_zoznam_predmetov()
if __name__ == '__main__':
main()