Home > Back-end >  QAQ thank for bosses to help do the Python
QAQ thank for bosses to help do the Python

Time:09-16

1, the students in the class add a students' comprehensive academic performance attributes, properties, GPA, and the range of 0.0 ~ 5.0 GPA, required in the input when this attribute need to check the legitimacy of the GPA attribute;
2, modify the class StudentList __update and update two functions, when the user to enter student id checks the existence of the students and when the living in according to the student's information first, and then continue to input the student's information;
3, increase the command to save, save student information to document information and loaded from a file students command load, save the student information file named StudentInfo. TXT.
The original code is as follows:
Lass, Student:
Def __init__ (self, No, Name, Gender, Age) :
Self. No=No
The self. The Name=Name
Self. Gender=Gender
The self. The Age=Age

Def show (self) :
Print (" % - 16 s % - 16 s % % - 8 - s - 4 d "% (self. No, the self. The Name, the self. The Gender, the self. The Age))

The class StudentList:
Def __init__ (self) :
The self. The students=[]
Def show (self) :
Print (" % - - 16 s 16 s % % % - 8 - s - 4 s "% (" No", "Name", "Gender", "Age"))
For s in the self. Students:
S.s how ()
Def __insert (self, s) :
I=0
While (i Self. Students [I]. No) :
I=I + 1
If (iPrint (s.N o + "exist")
Return False
Self. Students. Insert (I, s)
Print (" success ")
Return True

Def __update (self, s) :
Flag=False
For I in range (len (self. Students)) :
If (s.N o==self. Students [I] No) :
Self. Students [I]. Name=s.N ame
Self. Students [I]. Gender=s.G ender
Self. Students [I]. Age=s.A ge
Print (" success ")
Flag=True
Break
If (not flag) :
Print (" don't have the students ")
Return flag

Def __delete (self, No) :
Flag=False
For I in range (len (self. Students)) :
If (self. Students [I]. No==No) :
Del self. Students [I]
Print (" delete "success)
Flag=True
Break
If (not flag) :
Print (" don't have the students ")
Return flag

Def the delete (self) :
No=input (" No=")
If (No!="") :
Self. __delete (No)

Def insert (self) :
No=input (" No=")
Name=input (" Name=")
While True:
Gender=input (" Gender=")
If (Gender="male" or Gender==="female") :
Break
The else:
Print (" Gender is not vaild ")
Age=input (" Age=")
If (Age=="") :
Age=0
The else:
Age=int (Age)
If No!="" and the Name!="" :
Self. __insert (Student (No, Name, Gender, Age))
The else:
Print (" student id, name cannot be empty ")
Def update (self) :
No=input (" No=")
Name=input (" Name=")
While True:
Gender=input (" Gender=")
If (Gender="male" or Gender==="female") :
Break
The else:
Print (" Gender is not valid ")
Age=input (" Age=")
If (Age=="") :
Age=0
The else:
Age=int (Age)
If No!="" and the Name!="" :
Self. __update (Student (No, Name, Gender, Age))
The else:
Print (" student id, name cannot be empty ")


Def process (self) :
While True:
S=input (" & gt;" )
If (s=="show") :
The self. The show ()
Elif (s=="insert") :
The self. The insert ()
Elif (s=="update") :
The self. The update ()
Elif (s=="delete") :
The self. The delete ()
Elif (s=="exit") :
Break
The else:
Print (" show: show students ")
Print (" insert: insert a new student ")
Print (" update: insert a new student ")
Print (" delete: delete a student ")
Print (" exit: exit ")

St=StudentList ()
St. process ()

  • Related