vlady 0 Junior Poster in Training

Hello,

I need help to get all together. Pls see 2 different codes below .

1 code:
Represents format for final result paper called "vysvedcenie" (evaluation) for a particular student.

code:

def do_once(f):
    f()

def do_twice(f):
    f()
    f()

def do_four(f):
    do_twice(f)
    do_twice(f)

def hlavicka():
    print 'x',' '*40+'VYSVEDCENIE'+' '*46+'x'

def vertikal():
    print 'x'+' '*98+'x'


def horizontal():
    print 'xxxxx'*20

def udaje_student():
    print 'x  Meno, Priezvisko:',' '*40,'Skolsky rok:',' '*24+'x'
    print 'x  Kruzok:',' '*87,'x'

def hodnotenie():
    print 'x  Predmety:', ' '*30,'Hodnotenie:',' '*43+'x'

def zaver():
    print 'x  Celkovy prospech:',' '*77,'x'
    print 'x  Menovany student presiel do dalsieho rocnika (ano/nie):',' '*39,'x'

def format_vysvedcenie():
    horizontal()
    hlavicka()
    horizontal()
    do_once(vertikal)
    udaje_student()
    horizontal()
    do_once(vertikal)
    hodnotenie()
    do_four(vertikal)
    do_four(vertikal)
    horizontal()
    do_once(vertikal)
    zaver()
    do_once(vertikal)
    horizontal()

def main():
    print format_vysvedcenie()

if __name__ == '__main__':
    main()

output of this code is (attachement): output_vysvedcenie.doc

2 code:
Represents all information about students (who are defined inside Class). This code gives you all info about the particular student.

Here is a code:

class Cstudent():
    def __init__(self, name):
        self.name = name
        self.predmety = []
        self.priemer = []

    def add_subject(self, predmet):
        'pridanie predmentu danemu studentovi'
        self.predmety.append(predmet)

    def add_mark(self,predmet,mark):
        'pridanie znamky danemu studentovi'
        for i in self.predmety:
            if i.nazov == predmet:
                i.add_znamka(mark)

    def priemer_student(self):
        'vytvorenie priemernej znamky zo vsetkyvh predmetov pre daneho studenta'
        lstz=[]
        for predmet in self.predmety:
            for znamka in predmet.znamky:
                lstz.append(znamka)
        self.priemer= float(sum(lstz)) / float(len(lstz))

    def get_predmet(self,predmet):
        'nastroj, ktory vrati objekt predmetov'
        for i in self.predmety:
            if i.nazov==predmet:
                return i

    def __str__(self):
        return 'Meno studenta: %s \nCelkovy priemer: %s' % (self.name,self.priemer)

    def print_zoznam_predmetov(self):
        lst = []
        for prd in self.predmety:
            lst.append(str(prd))
        return '\n'.join(lst)


class Cpredmet():
    def __init__(self, nazov):
        self.nazov = nazov
        self.znamky = []
        self.absencia = 0

    def add_znamka(self, znamka):
        'prida znamky podla predmetu'
        self.znamky.append(znamka)

    def add_absent(self,cislo):
        'prida absent podla predmetu'
        self.absencia=cislo

    def average_predmet(self):
        'vrati priemer podla predmetu'
        if sum(self.znamky)==0:
            pass
        else:
            return float(sum(self.znamky)) / float(len(self.znamky))

    def __str__(self):
        return 'Predmet: %s, Znamky: %s, Priemer: %s, Absencia: %s hod' % \
            (self.nazov, str(self.znamky), self.average_predmet(), self.absencia)

def main():
# inicalizacia objektu student:
#-------------------------------
    janko = Cstudent('Janko Mrkvicka')
    janka = Cstudent ('Janka Vaskova')

# pridanie predmetu danemu objektu:
#-------------------------------
    janko.add_subject(Cpredmet('fyzika'))
    janko.add_subject(Cpredmet('english'))
    janko.add_subject(Cpredmet('matematika'))

    janka.add_subject(Cpredmet('dejepis'))
    janka.add_subject(Cpredmet('biologia'))
    janka.add_subject(Cpredmet('english'))
    janka.add_subject(Cpredmet('fyzika'))

# pridanie znamky danemu objektu:
#-------------------------------
    janko.add_mark(predmet='fyzika',mark=4)
    janko.add_mark(predmet='fyzika',mark=1)
    janko.add_mark(predmet='english',mark=1)
    janko.add_mark(predmet='matematika',mark=1)

    janka.add_mark(predmet='dejepis',mark=1)
    janka.add_mark(predmet='dejepis',mark=2)
    janka.add_mark(predmet='dejepis',mark=3)
    janka.add_mark(predmet='fyzika',mark=1)

# pridelenie k objektu student absenciu podla objektu predmet
    janko.get_predmet('fyzika').add_absent(cislo=3)
    janka.get_predmet('dejepis').add_absent(cislo=5)

# celkovy priemer na studenta:
    janko.priemer_student()
    janka.priemer_student()

# output:
#-------------------------------------
    print janko
    print janko.print_zoznam_predmetov()
    print '----------------------------------------------------------------------------------'
    print janka
    print janka.print_zoznam_predmetov()

if __name__ == '__main__':
    main()

output of this code is:

Meno studenta: Janko Mrkvicka
Celkovy priemer: 2.0
Predmet: fyzika, Znamky: [4, 1], Priemer: 2.5, Absencia: 3 hod
Predmet: english, Znamky: [1], Priemer: 1.0, Absencia: 0 hod
Predmet: matematika, Znamky: [1], Priemer: 1.0, Absencia: 0 hod
----------------------------------------------------------------------------------
Meno studenta: Janka Vaskova
Celkovy priemer: 1.75
Predmet: dejepis, Znamky: [1, 2, 3], Priemer: 2.0, Absencia: 5 hod
Predmet: biologia, Znamky: [], Priemer: None, Absencia: 0 hod
Predmet: english, Znamky: [], Priemer: None, Absencia: 0 hod
Predmet: fyzika, Znamky: [1], Priemer: 1.0, Absencia: 0 hod

* just for explanation:
Name: Janko Mrkvicka
total average: 2.0
Subject: physic, marks: [4,1], average: 2.5, Absence: 5 hours
...etc

What I want to do is:
to put together this 2 codes with this result: pls see in the attachement (output_vysvedcenie2.doc) how it should look like.

Pls can you help me to get this desired output?

I approciate your help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.