Untitled

mail@pastecode.io avatar
unknown
python
6 months ago
1.5 kB
0
Indexable
Never
class Student:
    def __init__(self,firstname,lastname):
        self.firstname = firstname
        self.lastname = lastname
class Class:
    def __init__(self,classname,students):
        self.classname = classname
        self.students = students
    def returnCommonStudentName(classInstance):
        d = {}
        mostcommonname = None
        students = classInstance.students
        for student in students:
            d[student.firstname] =  d.get(student.firstname,0)+1
        for name in d:
            if mostcommonname == None:
                mostcommonname = name
            elif d[name] > d[mostcommonname]:
                mostcommonname = name
        print(mostcommonname)
student1 = Student('simon','bary')
student2 = Student('simon','bary')
student3 = Student('yaron','bary')
student4 = Student('bob','bary')
student5 = Student('simon','bary')
student6 = Student('bob','bary')
sarr = [student1,student2,student3,student4,student5,student6]
class1 = Class('mego',sarr)
def returnstudentinstance():
    fname = input('enter firstname: ')
    lname = input('enter lastname: ')
    return Student(fname,lname)
def returnclassinstance():
    starr = [] 
    classname = input('enter class name')
    studentsnumber = int(input('enter students number'))
    for n in range(studentsnumber):
        student = returnstudentinstance()
        starr.append(student)
    return Class(classname,starr)