School

avatar

class School:

def \_\_init\_\_(self):

    self.student ={}

    self.history = []



def student\_exists(self, name):

    for grade in self.student:

      return name in self.student[grade]

    return False # dopo aver controllato tutte le liste, se non l´ho trovato non esite

        

def add\_student(self, name, grade):

    if self.student\_exists(name):

        self.history.append(False)

        return # alternativa di break, ma salta fuori dalla funzione

    if grade not in self.student:

        self.student[grade] = []

    self.student[grade].append(name)

    self.history.append(True)

       

def roster(self):

    ls\_st=[]

    for grade in sorted(self.student.keys()):

        ls\_st += sorted(self.student[grade])

    return ls\_st 

def grade(self, grade\_number):

    if grade\_number in self.student:

        return sorted(self.student[grade\_number])

    else:

        return []

        

def added(self):

    return self.history


0
0
0.000
2 comments
avatar

Thank you for your witness vote!
Have a !BEER on me!
To Opt-Out of my witness beer program just comment STOP below

0
0
0.000