Implementation of simple student management system with Python

Source: Internet
Author: User
Tags case statement

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.