Previously written in C + + and Java Student management system, also want to use Python to try, sure enough, "Life is too short, I use Python." Written in Python is more concise, the implementation of the prototype is less than 100 lines of code.
The code below
1 #!/usr/bin/python32 #Coding=utf-83 #__author__= ' Jeavenwong '4 5 6 7 8 #implement the Switch-case statement with9 classswitch (object):Ten def __init__(self, value): OneSelf.value =value ASelf.fall =False - - def __iter__(self): the """Return The match method once, then stop""" - yieldSelf.match - Raisestopiteration - + defMatch (Self, *args): - """indicate whether or not to enter a case suite""" + ifSelf.fallor notargs: A returnTrue at elifSelf.valueinchArgs#changed for v1.5, see below -Self.fall =True - returnTrue - Else: - returnFalse - in classStudent: - def __init__(self,name,age,id,grade): toSelf.next =None +Self.name =name -Self.age = Age theSelf.id =ID *Self.grade =Grade $ defShow (self):Panax Notoginseng Print('Name:', Self.name,' ','Age :', Self.age,' ','ID:', Self.id,' ','Grade:', Self.grade) - the classstulist: + def __init__(self): ASelf.head = Student ("', 0,0,0) the defdisplay (self): +p =Self.head.next - whileP: $ p.show () $p =P.next - defInsert (self): - Print('Please enter:') theName = input ('Name:') -Age = Input ('Age :')Wuyiid = input ('ID:') theGrade = input ('Grade:') -Newstu =Student (Name,age,id,grade) Wup =Self.head - whileP.next: Aboutp =P.next $P.next =Newstu - defquery (self): -Name = input ('Please enter the name of want to query:') -p =Self.head.next A whileP: + ifP.name = =Name: the p.show () -p =P.next $ the the defMain (): theStulist1 =stulist () theUser_input = input ('Please enter the OPcode:') - whileUser_input: in Print('a--insert/b--display/c--query/o--text/"'--defult') the forCaseinchswitch (user_input): the ifCase'a'): About Stulist1.insert () theUser_input = input ('Please enter the OPcode:') the Break the ifCase'b'): + Stulist1.display () -User_input = input ('Please enter the OPcode:') the BreakBayi ifCase'C'): the stulist1.query () theUser_input = input ('Please enter the OPcode:') - Break - ifCase ():#default the Print('Please enter the OPcode ...') theUser_input = input ('Please enter the OPcode:') the Break the - if __name__=="__main__": theMain ()
Here is the result of the operation:
Implementation of simple student management system with Python