我是靠谱客的博主 霸气钻石,最近开发中收集的这篇文章主要介绍用python设计学生管理系统_用python实现简易学生管理系统,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

1 #!/usr/bin/python3

2 #coding=utf-8

3

4

5 #实现switch-case语句

6 classswitch(object):7 def __init__(self, value):8 self.value =value9 self.fall =False10

11 def __iter__(self):12 """Return the match method once, then stop"""

13 yieldself.match14 raiseStopIteration15

16 def match(self, *args):17 """Indicate whether or not to enter a case suite"""

18 if self.fall or notargs:19 returnTrue20 elif self.value in args: #changed for v1.5, see below

21 self.fall =True22 returnTrue23 else:24 returnFalse25

26

27 classstudent:28 def __init__(self, name, age, id, grade):29 self.next =None30 self.name =name31 self.age =age32 self.id =id33 self.grade =grade34

35 defshow(self):36 print('name:', self.name, ' ', 'age:', self.age, ' ', 'id:', self.id, ' ', 'grade:', self.grade)37

38

39 classstulist:40 def __init__(self):41 self.head = student('', 0, 0, 0)42

43 defdisplay(self):44 p =self.head.next45 if p==None:46 print('no student data in database!')47 whilep:48 p.show()49 p =p.next50

51

52 definsert(self):53 print('please enter:')54 name = input('name:')55 age = input('age:')56 id = input('id:')57 grade = input('grade:')58 newstu =student(name, age, id, grade)59 p =self.head60 whilep.next:61 p =p.next62 p.next =newstu63

64 defquery(self):65 name = input('please enter the name you want to query:')66 p =self.head.next67 if p==None:68 print('no such student in database')69 whilep:70 if p.name ==name:71 p.show()72 p =p.next73

74 defdelete(self):75 name = input("please enter the student'name you want to delete:")76 p =self.head.next77 pre =self.head78 whilep:79 if p.name ==name:80 pre.next =p.next81 p.next =None82 print('the student info has been deleted!')83 break

84 else:85 pre =p86 p =p.next87

88

89 defmain():90 stulist1 =stulist()91 user_input = input('please enter the OPcode:')92 whileuser_input:93 print('a--insert/b--display/c--query/h or''--help/d--delete')94 for case inswitch(user_input):95 if case('a'):96 stulist1.insert()97 user_input = input('please enter the OPcode:')98 break

99 if case('b'):100 stulist1.display()101 user_input = input('please enter the OPcode:')102 break

103 if case('c'):104 stulist1.query()105 user_input = input('please enter the OPcode:')106 break

107 if case('d'):108 stulist1.delete()109 user_input = input('please enter your OPcode:')110 break

111 if case(): #default

112 print('please enter the OPcode...')113 user_input = input('please enter the OPcode:')114 break

115

116

117 if __name__ == "__main__":118 main()

最后

以上就是霸气钻石为你收集整理的用python设计学生管理系统_用python实现简易学生管理系统的全部内容,希望文章能够帮你解决用python设计学生管理系统_用python实现简易学生管理系统所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(47)

评论列表共有 0 条评论

立即
投稿
返回
顶部