python版学生管理系统


Posted in Python onJanuary 10, 2018

写一个学生管理系统,最好用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("----------输入有误,请重新输入!----------")

以下就是运行后的结果:

python版学生管理系统

python版学生管理系统

具体内容实现我还要研究研究,不过这个代码亲测已经可以运行了,小伙伴可以copy了。

过程中遇到的问题:

1. raw_input:我用的是3x的pyCharm,和2x的区别就在于不识别 raw_input,而要使用input。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Python 相关文章推荐
python实现将pvr格式转换成pvr.ccz的方法
Apr 28 Python
深入浅析python继承问题
May 29 Python
Python基于Pymssql模块实现连接SQL Server数据库的方法详解
Jul 20 Python
python取代netcat过程分析
Feb 10 Python
python的concat等多种用法详解
Nov 28 Python
10款最好的Python开发编辑器
Jul 03 Python
Python基于Tensor FLow的图像处理操作详解
Jan 15 Python
Python实现不规则图形填充的思路
Feb 02 Python
在Mac中PyCharm配置python Anaconda环境过程图解
Mar 11 Python
Python的控制结构之For、While、If循环问题
Jun 30 Python
matplotlib交互式数据光标mpldatacursor的实现
Feb 03 Python
pytorch 计算Parameter和FLOP的操作
Mar 04 Python
python实现用户管理系统
Jan 10 #Python
python的Tqdm模块的使用
Jan 10 #Python
python3.6 实现AES加密的示例(pyCryptodome)
Jan 10 #Python
Python设计模式之MVC模式简单示例
Jan 10 #Python
Python设计模式之命令模式简单示例
Jan 10 #Python
Python爬虫实例_利用百度地图API批量获取城市所有的POI点
Jan 10 #Python
Python之多线程爬虫抓取网页图片的示例代码
Jan 10 #Python
You might like
用PHP实现登陆验证码(类似条行码状)
2006/10/09 PHP
PHP yii实现model添加默认值的方法(两种方法)
2016/11/10 PHP
PHP水印类,支持添加图片、文字、填充颜色区域的实现
2017/02/04 PHP
Yii2 如何在modules中添加验证码的方法
2017/06/19 PHP
PHP+Ajax实现的检测用户名功能简单示例
2019/02/12 PHP
javascript 解决表单仍然提交即使监听处理函数返回false
2010/03/14 Javascript
utf-8编码引起js输出中文乱码的解决办法
2010/06/23 Javascript
jquery动态加载图片数据练习代码
2011/08/04 Javascript
javascript 实现 秒杀,团购 倒计时展示的记录 分享
2013/07/12 Javascript
js clearInterval()方法的定义和用法
2015/11/11 Javascript
基于Bootstrap里面的Button dropdown打造自定义select
2016/05/30 Javascript
jQuery选择器中的特殊符号处理方法
2017/09/08 jQuery
vue左右侧联动滚动的实现代码
2018/06/06 Javascript
详解vue添加删除元素的方法
2018/06/30 Javascript
在小程序中使用canvas的方法示例
2018/09/17 Javascript
Vue使用Proxy监听所有接口状态的方法实现
2019/06/07 Javascript
详解vue路由
2020/08/05 Javascript
解决vue elementUI 使用el-select 时 change事件的触发问题
2020/11/17 Vue.js
JavaScript实现商品评价五星好评
2020/11/30 Javascript
Collatz 序列、逗号代码、字符图网格实例
2017/06/22 Python
使用实现XlsxWriter创建Excel文件并编辑
2018/05/04 Python
python2.x实现人民币转大写人民币
2018/06/20 Python
django开发post接口简单案例,获取参数值的方法
2018/12/11 Python
使用Python创建简单的HTTP服务器的方法步骤
2019/04/26 Python
Python xlrd excel文件操作代码实例
2020/03/10 Python
Python气泡提示与标签的实现
2020/04/01 Python
canvas实现手机的手势解锁的步骤详细
2020/03/16 HTML / CSS
美国轮胎网站:Priority Tire
2018/11/28 全球购物
五水共治一句话承诺
2014/05/30 职场文书
2014年底个人工作总结
2015/03/10 职场文书
会计岗位职责范本
2015/04/02 职场文书
中学教代会开幕词
2016/03/04 职场文书
CocosCreator如何实现划过的位置显示纹理
2021/04/14 Javascript
详解PHP设计模式之依赖注入模式
2021/05/25 PHP
MySQL数据库完全卸载的方法
2022/03/03 MySQL
《堡垒之夜》联动《刺客信条》 4月7日正式上线
2022/04/06 其他游戏