侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

python版学生管理系统

Python  /  管理员 发布于 7年前   153

写一个学生管理系统,最好用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 Falsedef ageInputDebug(ageInput): # 检查年龄输入是否正确 if len(ageInput) == 2 and ageInput.isdigit() == True: return True else: return Falsedef IDInputDebug(IDInput): # 检查学号输入是否正确 if len(IDInput) == 8 and IDInput.isdigit() == True: return True else: return Falsedef nameListFunction(): # 显示单个学生姓名信息 nameList = [] for i in range(len(studentList)): if studentList[i]["name"] not in nameList:  nameList.append(studentList[i]["name"]) return nameListdef findNameLocation(studentname): # 通过名字找到学生位置 for j in range(len(studentList)): if studentList[j]["name"] == studentname:  return jdef 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。

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


  • 上一条:
    使用python 爬虫抓站的一些技巧总结
    下一条:
    python实现用户管理系统
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • 在python语言中Flask框架的学习及简单功能示例(0个评论)
    • 在Python语言中实现GUI全屏倒计时代码示例(0个评论)
    • Python + zipfile库实现zip文件解压自动化脚本示例(0个评论)
    • python爬虫BeautifulSoup快速抓取网站图片(1个评论)
    • vscode 配置 python3开发环境的方法(0个评论)
    • 近期文章
    • 智能合约Solidity学习CryptoZombie第四课:僵尸作战系统(0个评论)
    • 智能合约Solidity学习CryptoZombie第三课:组建僵尸军队(高级Solidity理论)(0个评论)
    • 智能合约Solidity学习CryptoZombie第二课:让你的僵尸猎食(0个评论)
    • 智能合约Solidity学习CryptoZombie第一课:生成一只你的僵尸(0个评论)
    • 在go中实现一个常用的先进先出的缓存淘汰算法示例代码(0个评论)
    • 在go+gin中使用"github.com/skip2/go-qrcode"实现url转二维码功能(0个评论)
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2016-10
    • 2016-11
    • 2018-04
    • 2020-03
    • 2020-04
    • 2020-05
    • 2020-06
    • 2022-01
    • 2023-07
    • 2023-10
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客