Need sample for following Python problems Hi Im practicing f
Need sample for following Python problems:
Hi, I\'m practicing for my quiz and I was able to do problem 1 as below. but I need sample for the other questions.
I just need an example for each question so I can study them.
Thank you!
1 Write class like Student (from home and Teacher (rom lecture slides) class Teacher:- Name none stuents 0 def make teacher name: tr students int)- Teacher: Teacher 0+ t name name- t students students return class Student(object): def init (self id, name): selfid self name name- selfhw self quiz 0- 2.Write a function that makes a Student or Teacher object and initializes the variables inside to values passed in as parameters 3.Write a function that reads a file in a certain format and builds a list of class objects with that info stored in each class object 4.Write a function that processes each class object in the list do do something interesting. 5.Write a function that writes the data in a list of class objects to a file in a specific format 6. Write a main program that pulls it all together to a complete program.Solution
2.
def makeStudent(id,name): # returns a student object
student= Student(id,name)
return student;
3.
def readfile() # reads file infile.txt ,the file must have id on one line and name on other for all objecst.
file=open(\"infile.txt\")
for f in file.readlines()
id=f
name=file.readlines()
studentlist.append(makestudent(id,name))
4.
def sortlstbyname() # sorts student list objects according to name
import operator
studentlsit.sort(Key=opeartor.attrgetter(\'name\'))
5.def writefile() # writes the students objects in the list to outfile.txt with id on first line and name on second for all obj
file=open(\"outfile.txt\",\"w\")
for student in studentlist
file.write(student.id+\"\ \")
file.write(student.name+\"\ \")
6. # write your student class here
studentlist[] # list for student objects
# write all functions here
# then call funtions in sequence as follows
readfile()
sortlistbyname()
writefile()
note[ change file path and assign an appropriate filepath there.]

