python版学生管理系统
作者:jeanalx 发布时间:2023-07-27 07:21:46
标签:python,管理系统
写一个学生管理系统,最好用python。
我都没学过python呢,只好开始临时抱佛脚,再到网上找找有没有例子看看,下面是我参照另一个博主写的,中间有一些和我不能融合的错误,我已经解决了。
input("\n\nPress the enter key to exit.")
def functionList(): # 定义功能菜单
print("---------请输入序号选择您要得功能---------")
print("")
print("-" * 14 + "1.查看学生信息" + "-" * 14)
print("-" * 42)
print("-" * 14 + "2.增加学生信息" + "-" * 14)
print("-" * 42)
print("-" * 14 + "3.删除学生信息" + "-" * 14)
print("-" * 42)
print("-" * 14 + "4.修改学生信息" + "-" * 14)
print("-" * 42)
print("-" * 14 + "5.查找系统学生" + "-" * 14)
print("-" * 42)
print("-" * 14 + "6.返回到上一级" + "-" * 14)
print("-" * 42)
print("-" * 14 + "7.退出学生系统" + "-" * 14)
print("")
def functionList2(): # 定义简单版功能菜单
print("---1:查看----2:增加-----3:删除----4:修改----")
print("-------5:查找-------6:返回------7:退出------")
def sexInputDebug(sexInput): # 检查性别输入是否正确
if len(sexInput) == 1 and (sexInput.lower() == "m" or sexInput.lower() == "f"):
return True
else:
return False
def ageInputDebug(ageInput): # 检查年龄输入是否正确
if len(ageInput) == 2 and ageInput.isdigit() == True:
return True
else:
return False
def IDInputDebug(IDInput): # 检查学号输入是否正确
if len(IDInput) == 8 and IDInput.isdigit() == True:
return True
else:
return False
def nameListFunction(): # 显示单个学生姓名信息
nameList = []
for i in range(len(studentList)):
if studentList[i]["name"] not in nameList:
nameList.append(studentList[i]["name"])
return nameList
def findNameLocation(studentname): # 通过名字找到学生位置
for j in range(len(studentList)):
if studentList[j]["name"] == studentname:
return j
def listFunction(): # 定义显示现有学生信息函数
for i in range(len(studentList)):
studentInfo = studentList[i]
print("姓名:%s--性别:%s--年龄:%s--学号:%s--备注:%s--" % (
studentInfo["name"], studentInfo["sex"], studentInfo["age"], studentInfo["studentID"], studentInfo["extra"]))
print("")
def addFunction(): # 定义增加学生函数
while True:
numInput =input("-----修改已经存在的学生备注请输入1\n-----------增加一个新的学生请输入2:")
if numInput == "2":
while True:
nameNoExistAdd = input("请输入您要增加的名字:")
nameList = nameListFunction()
if nameNoExistAdd in nameList:
print("%s在学生管理系统中已经存在" % nameNoExistAdd)
print("")
else:
newStudent = {}
newStudent["name"] = nameNoExistAdd
while True:
sexInput = input("----请输入%s的性别--f:man--m:women:" % nameNoExistAdd)
if sexInputDebug(sexInput) == True:
newStudent["sex"] = sexInput
break
else:
print("输入有误,请重新输入!")
while True:
ageInput = input("-------请输入%s2位数字表示的年龄:" % nameNoExistAdd)
if ageInputDebug(ageInput) == True:
newStudent["age"] = ageInput
break
else:
print("输入有误,请重新输入!")
while True:
IDInput = input("----------请输入%s的8位学号:" % nameNoExistAdd)
if IDInputDebug(IDInput) == True:
newStudent["studentID"] = IDInput
break
else:
print("输入有误,请重新输入!")
extraInput = input("----------请输入%s的备注:" % nameNoExistAdd)
newStudent["extra"] = extraInput
studentList.append(newStudent)
print("--------------%s已经添加到学生管理系统" % nameNoExistAdd)
print("")
print("姓名:%s--性别:%s--年龄:%s--学号:%s--备注:%s--" % (
newStudent["name"], newStudent["sex"], newStudent["age"], newStudent["studentID"],
newStudent["extra"]))
break
break
elif numInput == "1":
while True:
nameExistAdd = input("------请输入您要修改备注的学生的名字:")
nameList = nameListFunction()
if nameExistAdd in nameList:
extraExistAdd = input("-----------------请输入您要添加的备注:")
j = findNameLocation(nameExistAdd)
studentList[j]["extra"] = extraExistAdd
print("---------------备注已经添加--------------")
print("")
print("姓名:%s--性别:%s--年龄:%s--学号:%s--备注:%s--" % (
studentList[j]["name"], studentList[j]["sex"], studentList[j]["age"], studentList[j]["studentID"],
studentList[j]["extra"]))
print("")
break
else:
print("-----------------您输入的姓名不存在")
break
else:
print("----------------您输入的信息不正确")
def delFunction(): # 定义删除学生的函数
while True:
nameDel = input("---------------请输入您要删除的名字:")
studentNameList = nameListFunction()
if nameDel in studentNameList:
j = findNameLocation(nameDel)
del studentList[j]
print("-------------%s已经从学生管理系统中删除" % nameDel)
print("")
break
else:
print("------------------您要删除的名字不存在!")
def modifiFunction(): # 定义修改学生的函数
while True:
nameModifi = input("----------------请输入要修改的名字:")
studentNameList = nameListFunction()
if nameModifi in studentNameList:
print("------------请选择要修改的内容-----------")
print("--------------1:修改姓名---------------")
print("--------------2:修改性别---------------")
print("--------------3:修改年龄---------------")
print("--------------4:修改学号---------------")
print("--------------5:修改备注---------------")
while True:
choiceInput = input("请输入:")
if choiceInput == "1":
newNameInput = input("----------请输入新的姓名:")
j = findNameLocation(nameModifi)
studentList[j]["name"] = newNameInput
print("------------姓名已经更新------------")
print("")
break
elif choiceInput == "2":
while True:
newSexInput = input("----请输入新的性别--f:man--m:women---")
if sexInputDebug(newSexInput) == True:
j = findNameLocation(nameModifi)
studentList[j]["sex"] = newSexInput
print("-------------性别已经更新-------------")
print("")
break
else:
print("---------输入有误,请重新输入!---------")
break
elif choiceInput == "3":
while True:
newAgeInput = input("----------请输入新的年龄:")
if ageInputDebug(newAgeInput) == True:
j = findNameLocation(nameModifi)
studentList[j]["age"] = newAgeInput
print("------------年龄已经更新------------")
print("")
break
else:
print("----------入有误,请重新输入!-------")
break
elif choiceInput == "4":
while True:
newIDInput = input("----------请输入新的学号:")
if IDInputDebug(newIDInput) == True:
j = findNameLocation(nameModifi)
studentList[j]["studentID"] = newIDInput
print("------------学号已经更新------------")
print("")
break
else:
print("----------入有误,请重新输入!-------")
break
elif choiceInput == "5":
newExtraInput = input("----------请输入新的备注:")
j = findNameLocation(nameModifi)
studentList[j]["extra"] = newExtraInput
print("------------备注已经更新------------")
print("")
break
else:
print("---------输入有误,请重新输入!-------")
print("")
break
else:
print("-----------------您输入的名字不存在!")
print("")
def searchFunction(): # 定义搜索学生的函数
nameSearch = input("-------------请输入要查找的名字:")
print("")
nameList = nameListFunction()
if nameSearch in nameList:
print("-----------------%s在学生管理系统中-------------------" % nameSearch)
print("")
j = findNameLocation(nameSearch)
print("姓名:%s--性别:%s--年龄:%s--学号:%s--备注:%s--" % (
studentList[j]["name"], studentList[j]["sex"], studentList[j]["age"], studentList[j]["studenID"],
studentList[j]["extra"]))
print("")
else:
print("----------------%s不在学生管理系统中-----------------" % nameSearch)
print("")
# 默认学生信息系统内容
studentList = [{"name": "Frank", "sex": "f", "age": 33, "studentID": "312312", "extra": ""},
{"name": "Jane", "sex": "m", "age": 45, "studentID": "324235", "extra": ""}]
# 函数主体
print("-" * 11 + "欢迎来到学生管理系统" + "-" * 11)
print("")
print("")
functionList()
while True: # 进入循环,根据序号选择操作
userInput = input("----------------请输入您要选择的功能序号:")
print("")
if userInput == "1": # 显示现有学生和返回
listFunction()
functionList2()
continue
elif userInput == "2": # 使用增加函数和返回
addFunction()
functionList2()
continue
elif userInput == "3": # 使用删除函数和返回
delFunction()
functionList2()
continue
elif userInput == "4": # 使用修改函数和返回
modifiFunction()
functionList2()
continue
elif userInput == "5": # 使用搜索函数和返回
searchFunction()
functionList2()
continue
elif userInput == "6": # 返回功能列表
functionList()
continue
elif userInput == "7": # 退出
break
else:
print("----------输入有误,请重新输入!----------")
以下就是运行后的结果:
具体内容实现我还要研究研究,不过这个代码亲测已经可以运行了,小伙伴可以copy了。
过程中遇到的问题:
1. raw_input:我用的是3x的pyCharm,和2x的区别就在于不识别 raw_input,而要使用input。
来源:http://blog.csdn.net/jeanalx/article/details/70237011?locationNum=15&fps=1


猜你喜欢
- <?php session_start(); $_SESSION['username']="zhuzhao&
- 四、XML应用分类 总的说来的XML的应用可分为四类: (1)应用于客户需要与不同的数据源进行交互时。数据可能来自不同的数据库,他们都有各自
- MySQL中删除数据表是非常容易操作的, 但是你再进行删除表操作时要非常小心,因为执行删除命令后所有数据都会消失。语法以下为删除MySQL数
- heapq 模块提供了堆算法。heapq是一种子节点和父节点排序的树形数据结构。这个模块提供heap[k] <= heap[2*k+1
- 经典神经网络的改进点名称改进点VGG161、使用非常多的3*3卷积串联,利用小卷积代替大卷积,该操作使得其拥有更少的参数量,同时会比单独一个
- ---- Oracle是关系型数据库管理系统,它功能强大、性能卓越,在当今大型数据库管理系统中占有重要地位。在我们开发的一MIS
- 一个JavaScript代码编写的图片展示特效,效果很棒。效果图:演示:<!DOCTYPE HTML PUBLIC "-//
- 每日凌晨2:00进行dump对相应数据库进行备份,同时对相应数据库进行binlog日志文件更新。如果发现数据库错误,只需要先恢复上一个dum
- 这里要注意的是js的时间戳是13位,php的时间戳是10位,转换函数如下: var nowtime = (new Date).getTime
- 本文实例讲述了Python列表计数及插入的用法。分享给大家供大家参考。具体如下:word=['a','b',
- 本文实例讲述了Go语言实现定时器的方法。分享给大家供大家参考。具体实现方法如下:package mainimport ( &quo
- 远程服务器配置可以使得数据库管理员在服务器以外的主机上连接到一个SQL Server实例,以便管理员在没有建立单据连接的情况下在其他的SQL
- 导语哈喽!哈喽!我是木木子!今日游戏更新——中国象棋上线啦!中国象棋是一种古老的棋类游戏,大约有两千
- 前言文章中的代码是参考基于Pytorch的特征图提取编写的代码本身很简单这里只做简单的描述。1. 效果图先看效果图(第一张是原图,后面的都是
- 由于 MySQL 5.7 版本的 root 密码是首次启动时随机生成的,并且还要求必须修改后才能使用,所以有了本文:使用 shell 脚本完
- 本文实例讲述了ThinkPHP结合AjaxFileUploader实现无刷新文件上传的方法。分享给大家供大家参考。具体实现方法分析如下:首先
- 1. dbm UNIX键-值数据库dbm是面向DBM数据库的一个前端,DBM数据库使用简单的字符串值作为键来访问包含字符串的记录。dbm使用
- MySQL分区表概述我们经常遇到一张表里面保存了上亿甚至过十亿的记录,这些表里面保存了大量的历史记录。 对于这些历史数据的清理是一个非常头疼
- 扪心自问,你真正了解你卖给用户的是什么玩意么?你所认为革命性的,一定会震惊世界的功能、特色,用户真的买单么?我的意思是,我们总是习惯性的忘记
- 如下所示:numpy.power(x1, x2)数组的元素分别求n次方。x2可以是数字,也可以是数组,但是x1和x2的列数要相同。 >