网络编程
位置:首页>> 网络编程>> Python编程>> python实现学生信息管理系统源码

python实现学生信息管理系统源码

作者:~浮生~  发布时间:2021-07-26 17:02:06 

标签:python,学生,管理系统

本文实例为大家分享了python实现学生信息管理系统的具体代码,供大家参考,具体内容如下

代码如下:

Project.py文件内容:


class Student(object):
# 建立学生信息储存的列表(嵌套的方式)
studentInformation = []
# 对学生对象的数据进行说明
studentShow = ["学号:", "姓名:", "年龄:"]

# 录入学生
def addstudent(self):
 sno = input("请输入学号:")
 name = input("请输入姓名:")
 sage = input("请输入年龄:")
 # 建立一个列表,用于暂时存储
 student = [sno, name, sage]
 # 加入学生(判断学号是否重复)
 x = 0
 # 刚开始录入学生时,学号不可能重复
 if len(self.studentInformation) == 0:
  self.studentInformation.append(student)
 # 判断重复
 else:
  while x < len(self.studentInformation):
   if self.studentInformation[x][0] != sno:
    x += 1
   else:
    print("学号重复!!!\n请重新输入序号!!!")
    break
  else:
   self.studentInformation.append(student)
   print("加入成功!!!")

# 输出学生
def showstudent(self):
 print("学生信息输出如下:")
 for i in range(len(self.studentInformation)):
  print(self.studentShow[0]+self.studentInformation[i][0], end=" ")
  print(self.studentShow[1] + self.studentInformation[i][1], end=" ")
  print(self.studentShow[2] + self.studentInformation[i][2])

# 删除学生
def deletestudent(self):
 x = 0
 sno = input("请输入学生学号:")
 while x < len(self.studentInformation):
  if self.studentInformation[x][0] == sno:
   del self.studentInformation[x]
   print("删除学生成功!!!")
   break
  else:
   x += 1
 else:
  print("不存在当前学生!!!")

# 查询学生
def selectstudent(self):
 x = 0
 sno = input("请输入查询学生的学号")
 while x < len(self.studentInformation):
  if self.studentInformation[x][0] == sno:
   print(self.studentShow[0] + self.studentInformation[x][0], end=" ")
   print(self.studentShow[1] + self.studentInformation[x][1], end=" ")
   print(self.studentShow[2] + self.studentInformation[x][2])
   break
  else:
   x += 1
 else:
  print("未查询到当前学生!!!")

# 修改学生
def changestudent(self):
 x = 0
 sno = input("请输入修改学生的学号:")
 while x < len(self.studentInformation):
  if self.studentInformation[x][0] == sno:
   name = input("请输入修改后的姓名:")
   sage = input("请输入修改后的年龄:")
   self.studentInformation[x][1] = name
   self.studentInformation[x][2] = sage
   print("修改成功!!!")
   break
  else:
   x += 1

# 界面打印
@staticmethod
def printui():
 print("输入:0 --退出程序--")
 print("输入:1 --录入学生--")
 print("输入:2 --输出学生--")
 print("输入:3 --删除学生--")
 print("输入:4 --查询学生--")
 print("输入:5 --修改学生--")

# 程序调用
def run(self):
 self.printui()
 number = input("请输入功能前面的代码:")
 # 无限循环
 var = 1
 while var == 1:
  if int(number) == 1:
   self.addstudent()
   self.printui()
   number = input("请输入功能前面的代码:")
  elif int(number) == 2:
   self.showstudent()
   self.printui()
   number = input("请输入功能前面的代码:")
  elif int(number) == 3:
   self.deletestudent()
   self.printui()
   number = input("请输入功能前面的代码:")
  elif int(number) == 4:
   self.selectstudent()
   self.printui()
   number = input("请输入功能前面的代码:")
  elif int(number) == 5:
   self.changestudent()
   self.printui()
   number = input("请输入功能前面的代码:")
  elif int(number) == 0:
   break
  else:
   print("您输入的序号不对!\n请重新输入!")
   self.printui()
   number = input("请输入功能前面的代码:")
 else:
  print("再见!")
  exit()

text.py文件:


from Project import Student
# 实例化对象
stu = Student()
stu.run()

运行结果:

python实现学生信息管理系统源码

python实现学生信息管理系统源码

python实现学生信息管理系统源码

python实现学生信息管理系统源码

python实现学生信息管理系统源码

来源:https://blog.csdn.net/qq_52889967/article/details/113886306

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com