栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python项目:学生管理系统

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python项目:学生管理系统

学生管理系统 主要功能
  • 学生管理系统主要有增加、删除、查询、修改四个功能。那么我们就安装脑图的思维顺序,来对我们的程序进行编写

  • 先做个学生表,运用之前课程学习的知识将学生表制作处理,然后将学生信息保存到文本文件里,用空格来隔开每个字段。
    行——记录——元组
    列——字段——属性
  • 注意要将文件保存的方式为ANSI
构建框架
  • 登录界面

  • 建立主菜单

  • 建立二级菜单

- 建立各二级菜单
  • 添加学生信息

  • 查询所有学生信息

  • 以学号查询学生信息

  • 以姓名查询学生信息

  • 修改学生姓名

  • 修改各项数据

  • 修改菜单

  • 删除信息

  • 运行大概情况

大致代码如下
def add_student():  # 添加学生信息
    sql = 'insert into students values(%s, %s, %s, %s, %s, %s, %s, %s )'
    print('录入信息:')
    id = int(input('id:'))
    name = input('name:')
    gender = input('gender:')
    age = int(input('age:'))
    class_grade = input('class_grade:')
    major = input(('major:'))
    college = input('college:')
    telephone = input('telephone:')
    row = (id, name, gender, age, class_grade, major, college, telephone)
    print(row)
    count = cursor.execute(sql, row)
    if count > 0:
        # 提交数据修改
        conn.commit()
        # 提示用户操作成功
        print('记录插入成功!')
    else:
        # 提示操作失败
        print('记录插入失败!')

def dis_all_stu():  # 查询所有学生信息
    cursor.execute('select * from student ')
    # 获取全部学生数据
    students = cursor.fetchall()
    # print(students)
    for stu in students:
        # print(students[i])
        print('{}t{}t{}t{}t{}t{}t{}t{}'.format(stu[0], stu[1], stu[2], stu[3], stu[4],stu[5], stu[6], stu[7]))

def id_dis_stu():  # 以学号查询学生信息
    # 执行SQL查询
    id = input('输入待查id:')
    cursor.execute('select * from students where id = %s', (id))
    # 获取全部学生数据
    student = cursor.fetchall()
    if student == []:
            print(f'未查到学号为{id}的学生!')
    else:
        for i in student:
            print('{}t{}t{}t{}t{}t{}t{}t{}'.format(i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7]))

def name_dis_stu():   # 以姓名查询学生信息
    # 执行SQL查询
    name = input('输入待查name:')
    cursor.execute('select * from students where name = %s', (name))
    # 获取全部学生数据
    student = cursor.fetchall()
    if student == []:
            print(f'未查到姓名为{name}的学生!')
    for i in student:
        print('{}t{}t{}t{}t{}t{}t{}t{}'.format(i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7]))

# 修改学生姓名
def modify_stu_name():
    while True:
        id = input('输入待修改信息的id:')
        cursor.execute('select * from students where id = %s', (id))
        student = cursor.fetchall()
        if student == []:
            print(f'未查到学号为{id}的学生!')
        else:
            new_name = input('输入修改后的姓名:')
            count = cursor.execute('update students set name = %s where id = %s', (new_name, id))
            if count > 0:
                conn.commit()
                print('数据修改成功!')
                break
            else:
                print('数据修改失败!')

def modify_stu_gender():
    while True:
        id = input('输入待修改信息的id:')
        cursor.execute('select * from students where id = %s', (id))
        student = cursor.fetchall()
        if student == []:
            print(f'未查到学号为{id}的学生!')
        else:
            new_gender = input('输入修改后的性别:')
            count = cursor.execute('update students set gender = %s where id = %s', (new_gender, id))
            if count > 0:
                conn.commit()
                print('数据修改成功!')
                break
            else:
                print('数据修改失败!')

def modify_stu_age():
    while True:
        id = input('输入待修改信息的id:')
        cursor.execute('select * from students where id = %s', (id))
        student = cursor.fetchall()
        if student == []:
            print(f'未查到学号为{id}的学生!')
        else:
            new_age = input('输入修改后的年龄:')
            count = cursor.execute('update students set age = %s where id = %s', (new_age, id))
            if count > 0:
                conn.commit()
                print('数据修改成功!')
                break
            else:
                print('数据修改失败!')

def modify_stu_cg():
    while True:
        id = input('输入待修改信息的id:')
        cursor.execute('select * from students where id = %s', (id))
        student = cursor.fetchall()
        if student == []:
            print(f'未查到学号为{id}的学生!')
        else:
            new_class_grade = input('输入修改后的班级:')
            count = cursor.execute('update students set class_grade = %s where id = %s', (new_class_grade, id))
            if count > 0:
                conn.commit()
                print('数据修改成功!')
                break
            else:
                print('数据修改失败!')

def modify_stu_major():
    while True:
        id = input('输入待修改信息的id:')
        cursor.execute('select * from students where id = %s', (id))
        student = cursor.fetchall()
        if student == []:
            print(f'未查到学号为{id}的学生!')
        else:
            new_major = input('输入修改后的专业:')
            count = cursor.execute('update students set major = %s where id = %s', (new_major, id))
            if count > 0:
                conn.commit()
                print('数据修改成功!')
                break
            else:
                print('数据修改失败!')

def modify_stu_college():
    while True:
        id = input('输入待修改信息的id:')
        cursor.execute('select * from students where id = %s', (id))
        student = cursor.fetchall()
        if student == []:
            print(f'未查到学号为{id}的学生!')
        else:
            new_college = input('输入修改后的学院:')
            count = cursor.execute('update students set college = %s where id = %s', (new_college, id))
            if count > 0:
                conn.commit()
                print('数据修改成功!')
                break
            else:
                print('数据修改失败!')

def modify_stu_phone():
    while True:
        id = input('输入待修改信息的id:')
        cursor.execute('select * from students where id = %s', (id))
        student = cursor.fetchall()
        if student == []:
            print(f'未查到学号为{id}的学生!')
        else:
            new_phone = input('输入修改后的电话:')
            count = cursor.execute('update students set telephone = %s where id = %s', (new_phone, id))
            if count > 0:
                conn.commit()
                print('数据修改成功!')
                break
            else:
                print('数据修改失败!')

def modify_student():  # 修改学生信息
    while True:
        print('n查询学生记录n')
        print('=================')
        print('1.修改姓名')
        print('2.修改性别')
        print('3.修改年龄')
        print('4.修改班级')
        print('5.修改专业')
        print('6.修改学院')
        print('7.修改电话')
        print('8.返回上级菜单')
        print('=================')
        mc4 = int(input('输入菜单号:'))
        if mc4 == 1:
            modify_stu_name()
        elif mc4 == 2:
            modify_stu_gender()
        elif mc4 == 3:
            modify_stu_age()
        elif mc4 == 4:
            modify_stu_cg()
        elif mc4 == 5:
            modify_stu_major()
        elif mc4 == 6:
            modify_stu_college()
        elif mc4 == 7:
            modify_stu_phone()
        else:
            break


def query_student():  # 查询学生记录
    while True:
        print('n查询学生记录n')
        print('=================')
        print('1.按学号查询学生记录')
        print('2.按姓名查询学生记录')
        print('3.查询全部学生记录')
        print('4.返回上级菜单')
        print('=================')
        mc3 = int(input('输入菜单号:'))
        if mc3 == 1:
            id_dis_stu()
        elif mc3 == 2:
            name_dis_stu()
        elif mc3 == 3:
            dis_all_stu()
        else:
            break



# 删除信息
def del_stu():
    # 执行SQL查询
    id = input('输入待查学号:')
    count = cursor.execute('delete from students where id = %s', (id))

    if count > 0:
        # 提交数据修改
        conn.commit()
        print('记录删除成功!')
    else:
        print('记录删除失败!')


def login():
    username = input('输入用户名: ')
    password = input('输入密码: ')
    if username == 'lrx' and password == '000':
        while True:
            print('n学生信息管理n')
            print('===========')
            print('1. 增加学生记录')
            print('2. 查询学生记录')
            print('3. 修改学生记录')
            print('4. 删除学生记录')
            print('5. 返回上级菜单')
            print('===========')
            mc2 = int(input('输入菜单号: '))
            if mc2 == 1:
                add_student()
            elif mc2 == 2:
                query_student()
            elif mc2 == 3:
                modify_student()
            elif mc2 == 4:
                del_stu()
            else:
                break
    else:
        print('n用户名或密码错误,请重新登录n')

# 主程序
while True:
    print('用户登录')
    print('==========')
    print('1.登录')
    print('2.退出')
    print('==========')
    mc1 = int(input('输入菜单号: '))
    if mc1 == 1:
        login()
    elif mc1 == 2:
        print('n谢谢使用本程序n')
        break

程序都是课上老师交的,还是自己的思维和程序运用能力不足。这个系统各项项目还十分不完善还是一个简陋的一个程序,还有许多需要改进的地方,需要慢慢改进。
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/689588.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号