这篇文章主要为大家详细介绍了python实现学生管理系统,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
python写的简单的学生管理系统,练习python语法。
可以运行在windows和linux下,python 2.7。
#!/usr/local/bin/python # -*- coding:utf-8 -*- im<mark style="color:transparent">来源gaodaimacom搞#^代%!码网</mark>port os import re #定义学生类 class Student: def __init__(self): self.name = '' self.ID = '' self.score = 0 #根据学生分数进行从大到小的冒泡排序 def BuddleSortByScore( stulist ): n = len( stulist ) for i in range( n ): for j in range( n - i - 1): if stulist[j].score = 0 and stu.score <= 100: # break #利用正则表达式来判断分数是否符合标准 if re.match( "^[0-9]" ,str(stu.score) ) and stu.score= 0 : break else: print u"分数不满足实际情况,应该为0--100之间的数字!" if Add( stulist , stu ) == 1: print u"学生信息增加成功!" else: print u"学生信息增加失败!" elif nChoose == "2": QueryMenu( stulist ) elif nChoose == "3": DeleteMenu( stulist ) elif nChoose == "4": PrintAllStudentInfo( stulist ) elif nChoose == "5": BuddleSortByScore( stulist ) print "Do you want to save the sorted result?" choose = raw_input("please input your choice:Y/N:") if choose == 'Y' or choose == 'y': file_object = open("students.txt","w+") for stu2 in stulist: file_object.write(stu2.ID) file_object.write(" ") file_object.write(stu2.name) file_object.write(" ") file_object.write(str(stu2.score)) file_object.write("\r\n") elif nChoose == "6": return else: print u"输入有误,请重新输入!" #测试函数部分 if __name__ == '__main__': #定义一个列表用来存储所有学生的信息 stulist = [] #初始化,从文件中读取信息 Init( stulist ) #菜单函数 menu( stulist )
运行需要读写文件Students.txt。文件格式如下图:
更多学习资料请关注专题《管理系统开发》。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持gaodaima搞代码网。
以上就是python实现学生管理系统的详细内容,更多请关注gaodaima搞代码网其它相关文章!