学生信息管理系统Python面向对象版

yipeiwu_com5年前Python基础

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

"""
  程序名称:学生信息管理系统
  版本信息:0.1
  开发者:飞宇
  开始时间:2018.3.23 19:45
  版本更新时间:2018.4.2 23:08
  格式:IPO
  OOP面向对象
"""
# 学生类
class Student:
  def __init__(self, stuId, name, age, sex, dept, nation):
    self.stuId = stuId
    self.name = name
    self.age = age
    self.sex = sex
    self.dept = dept
    self.nation = nation
  def studentoop(self):
    pass
# 管理系统类
class Sys:
  def __init__(self):
    pass
  # 展示系统菜单
  def show_menu(self):
    print("=" * 56)
    print("")
    print("         学生信息管理系统 v1.0")
    print("")
    print("          1:添加用户信息")
    print("          2:查询用户信息")
    print("          3:修改用户信息")
    print("          4:删除用户信息")
    print("          5:显示用户信息")
    print("          0:退出系统")
    print("")
    print("=" * 56)
  # 输入学生菜单
  def getinfo(self):
    global new_stuId
    global new_name
    global new_age
    global new_sex
    global new_dept
    global new_nation
    new_stuId = input("请输入学号:")
    new_name = input("请输入名字:")
    new_age = input("请输入年龄:")
    new_sex = input("请输入性别:")
    new_dept = input("请输入专业:")
    new_nation = input("请输入民族:")
  # 添加学生信息
  def add_stus(self):
    #调用getinfo方法
    self.getinfo()
    #以ID为Key,将新输入的信息赋值给Student类
    students[new_stuId] = Student(new_stuId, new_name, new_age, new_sex, new_dept, new_nation)
    # 打印添加的学生信息
    print("学号:%s" % students[new_stuId].stuId, "姓名:%s" % students[new_stuId].name, "年龄:%s" % students[new_stuId].age,
       "性别:%s" % students[new_stuId].sex, "专业:%s" % students[new_stuId].dept, "民族:%s" % students[new_stuId].nation)
    print("=" * 56)
  # 查询学生信息
  def find_stus(self):
    find_nameId = input("请输入要查的学号")
    if find_nameId in students.keys():
      print("学号:%s\t名字:%s\t年龄:%s\t性别:%s\t名字:%s\t民族:%s" %
         (students[new_stuId].stuId, students[new_stuId].name, students[new_stuId].age,
          students[new_stuId].sex, students[new_stuId].dept, students[new_stuId].nation))
    else:
      print("查无此人")
    print("=" * 56)
  # 修改学生信息
  def alter_stus(self):
    alterId = input("请输入你要修改学生的学号:")
    self.getinfo()
    # 当字典中Key相同时,覆盖掉以前的key值
    if alterId in students.keys():
      students[new_stuId] = Student(new_stuId, new_name, new_age, new_sex, new_dept, new_nation)
      del students[alterId]
    else:
      print("查无此人")
    print("=" * 56)
  # 删除学生信息
  def del_stus(self):
 
    cut_nameID = input("请输入要删除的学号:")
    if cut_nameID in students.keys():
      del students[cut_nameID]
    else:
      print("查无此人")
    print("=" * 56)
  # 显示学生信息
  def show_stus(self):
 
    for new_stuId in students:
      print("学号:%s\t名字:%s\t年龄:%s\t性别:%s\t名字:%s\t民族:%s" %
         (students[new_stuId].stuId, students[new_stuId].name, students[new_stuId].age,
          students[new_stuId].sex, students[new_stuId].dept, students[new_stuId].nation))
    print("=" * 56)
  # 退出
  def exit_stus(self):
    print("欢迎下次使用")
    exit()
# 创建系统对象
sys = Sys()
# 定义一个容器来存储学生信息
students = {}
sys.show_menu()
while True:
  choice = int(input("请选择功能:"))
  if choice == 1:
    sys.add_stus()
  elif choice == 2:
    sys.find_stus()
  elif choice == 3:
    sys.alter_stus()
  elif choice == 4:
    sys.del_stus()
  elif choice == 5:
    sys.show_stus()
  elif choice == 0:
    sys.exit_stus()
  else:
    print("您输入有误,请重新输入")

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python多线程http下载实现示例

测试平台 Ubuntu 13.04 X86_64 Python 2.7.4 花了将近两个小时, 问题主要刚开始没有想到传一个文件对象到线程里面去, 导致下载下来的文件和源文件MD5不一样...

Python标准库sched模块使用指南

事件调度 sched 模块内容很简单,只定义了一个类。它用来最为一个通用的事件调度模块。 class sched.scheduler(timefunc, delayfunc) 这个类定义...

Python实现按学生年龄排序的实际问题详解

前言 本文主要给大家了关于利用Python按学生年龄排序的相关内容,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍: 问题:定义一个Class:包含姓名name、性别gen...

Python编程使用NLTK进行自然语言处理详解

Python编程使用NLTK进行自然语言处理详解

自然语言处理是计算机科学领域与人工智能领域中的一个重要方向。自然语言工具箱(NLTK,NaturalLanguageToolkit)是一个基于Python语言的类库,它也是当前最为流行的...

利用Python半自动化生成Nessus报告的方法

利用Python半自动化生成Nessus报告的方法

0x01 前言 Nessus是一个功能强大而又易于使用的远程安全扫描器,Nessus对个人用户是免费的,只需要在官方网站上填邮箱,立马就能收到注册号了,对应商业用户是收费的。当然,个人用...