[Flying pulp Baidu pilot group zero-based Python] study notes

Flying paddle Baidu pilot group work

The Paddle Pilot Group is an interest community for Paddle Paddle developers, providing developers with a wealth of local technology salons, Meetups, and online communication platforms, open to all developers interested in artificial intelligence and deep learning. With the enthusiastic support of the leaders and members of the pilot groups in various cities/colleges, the Paddle Pilot Group has established 132 communities, covering 28 provincial-level administrative regions and 108 colleges and universities, and continues to grow. Developers are welcome to join the pilot group, get to know more local technology colleagues, build an open source community, and share open source achievements and happiness.

Define the Student class, including name, dob, age, gender, and score attributes, including the top3 method to return the student's largest 3 grades (repeatable), and the sanitize method to turn negative scores into positive ones. The score may be a typo. Declare the stu_list object array to store all student objects. Finally, output all student information including name, birthday, age, gender, and the highest 3 scores.
insert image description here

# 请在此处完成代码
def opentext(txt):
    with open(txt) as f:
        line = f.readline()
        # print(line.strip().split(','))
    return line.strip().split(',')

      

class Student():
    def __init__(self, name, dob, age, gender, score):
        self.name = name
        self.dob = dob
        self.age = age
        self.gender = gender
        self.score = score

    def name(self):
        return self.name

    def dob(self):
        return self.dob
    
    def age(self):
        return self.age

    def gender(self):
        return self.gender

    def top3(self):
        newlist = []
        for t in self.score:
            t = int(t)
            if t < 0 :
                t = -t
            newlist.append(t)
        return sorted(newlist)[::-1][:3]
            

def printf(textname):
    txtlist = opentext(textname)
    name = txtlist.pop(0)
    dob = txtlist.pop(0)
    age = txtlist.pop(0)
    gender = txtlist.pop(0)
    student = Student(name, dob, age, gender, txtlist)
    # print(student.name)a
    print(f'姓名:{student.name} 生日:{student.dob} 年龄:{student.age} 性别:{student.gender} 分数:{student.top3()}')


printf('work/stu1.txt')
printf('work/stu2.txt')
printf('work/stu3.txt')
printf('work/stu4.txt')

stu5.txt Specialty students,2020-10-5,20,'Male',180,87,98,77,76,92,58,-76,84,69,-47
stu6.txt Specialty students,2020-10 -6,20,'Female',230,76,48,82,88,92,58,-91,84,69,-68 The
above two txt files can be found under the work path.

Define Spostudent and Artstudent as subclasses of Student, and add spe as a specialty score in the properties of the subclass. The top3 method included in Spostudent returns the lowest 3 scores (repeatable), Artstudent includes the top3 method returns the highest 3 scores (repeatable), and finally uses polymorphism to output the names and birthdays of 2 special students , age, gender, score, specialty score.
insert image description here


# 请在此处完成代码
class Spostudent(Student):
    def __init__(self, name, dob, age, gender, score, spe):
        Student.__init__(self, name, dob, age, gender, score)
        self.spe = spe

    def spe(self):
        return self.spe
    
class Artstudent(Student):
    def __init__(self,  name, dob, age, gender, score):
        Student.__init__(self, name, dob, age, gender, score)
    
    def top3(self):
        newlist = []
        for t in self.score:
            t = int(t)
            if t < 0 :
                t = -t
            newlist.append(t)
        return sorted(newlist)[0:3]

def printf(text,a):
    txtlist = opentext(text)
    name = txtlist.pop(0)
    dob = txtlist.pop(0)
    age = txtlist.pop(0)
    gender = txtlist.pop(0)
    spe = txtlist.pop(0)
    spostudent = Spostudent(name, dob, age, gender, txtlist, spe)
    artstudent = Artstudent(name, dob, age, gender, txtlist)
    if a == 0:
        a = spostudent.top3()
    else:
        a = artstudent.top3()
    print(f'姓名:{spostudent.name} 生日:{spostudent.dob} 年龄:{spostudent.age} 性别:{spostudent.gender} 分数:{a} 特长分:{spostudent.spe}')

        
printf('work/stu5.txt', 1)


        
printf('work/stu5.txt', 1)
printf('work/stu6.txt', 0)

Course experience

The six days have passed very quickly, and there is still no end to it. The experience is over before it is good. I will continue to pay attention to it after I have gained a lot.
The use of the platform is like a reference book
.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324162850&siteId=291194637