基于python的学生信息管理系统

完整代码

import pymysql
index='''
            +---------------------+
                    首页
            欢迎来到学生信息管理系统
            1.登陆
            2.注册
            3.quit(按任意键退出)
            +---------------------+
            '''
login='''
            +---------------------+
                    登陆
            欢迎来到学生信息管理系统
            请输入用户名和密码
            +---------------------+
            '''
tishi='''
            欢迎 {} 来到教学管理系统
                请输入您的操作
                    操作平台
            +---------------------+
            1.查询信息
            2.修改信息
            3.增加信息
            4.删除信息
            5.quit(返回登陆页面)
            +---------------------+
            '''
zhuce='''           
                            注册
            +---------------------—----------------+
            学号    姓名     性别    出生日期     班级   
            +--------------------------------------+  
            '''

select_stu_mas='''
            +---------------------+
            1.查询成绩
            2.查询本人信息
            3.quit(任意键退出)
            +---------------------+
            '''
update_mas_dif='''
            +---------------------+
            '''
maseger_start='''
            +---------------------—--------------------------------------------+
            学号        姓名         性别          出生日期                班级   
            '''
maseger_stop='''
            +------------------------------------------------------------------+
            '''
maseger_degree_start='''
            +------------------------------------------------------------------+
            学号            课程号             成绩
            '''
maseger_degree_stop='''
            +------------------------------------------------------------------+
            '''
def select_mas(user,cur):
    while True:
        try:
            action = input(select_stu_mas).strip()
            #查询个人信息
            if action == '2':
                sql = 'select * from student where sno="{}"'.format(user)
                #print(sql)
                cur.execute(sql)
                data=cur.fetchone()
                print(maseger_start)
                print(data)
                print(maseger_stop)
            #查询成绩:
            elif action=='1':
                sql = 'select * from score where sno="{}"'.format(user)
                cur.execute(sql)
                data = cur.fetchall()
                print(maseger_degree_start)
                for i in data:
                    print(i)
                print(maseger_degree_stop)
            else:
                print('            您已安全退出个人查询页面!')
                break
        except Exception as e:
            print(e)
def update_mas(user,cur):
    pass
def insert_mas(user,cur):
    pass
def delete_mas(user,cur):
    pass
def login_student(results,user_password):
    try:
        if results[0][0] and results[0][1]==user_password:
            #print(tishi.format(results[0][0]))
            return True
    except Exception as e:
        #print('            错误原因:',e)
        return False

def handle_mas(user,cur):
    while True:
        action = input(tishi.format(user)).strip()
        if action=='1':
            select_mas(user,cur)
        elif action=='2':
            update_mas(user)
        elif action=='3':
            insert_mas(user)
        elif action=='4':
            delete_mas(user)
        elif action=='5':
            return False
            break
        else:
            print('            输入错误,请重新输入:')
def zhuce_mas(cur):
    while True:
        student_zhuce_mas=input(zhuce).split()
        sno=student_zhuce_mas[0];
        sname=student_zhuce_mas[1];
        ssex=student_zhuce_mas[2];
        sbirthday=student_zhuce_mas[3];
        class_no=student_zhuce_mas[4];
        login_password = input("            请输入密码:").strip()
        sql1='insert into student values("{}","{}","{}","{}","{}");'.format(sno,sname,ssex,sbirthday,class_no)
        sql2='insert into login_student values("{}","{}");'.format(sno,login_password)
        print(sql1)
        print(sql2)
        try:
            cur.execute(sql1)
            cur.execute(sql2)
        except Exception as e:
            print(e)
        finally:
            print('            注册成功!返回登陆页面')
            break
#连接数据库
def main():
    try:
        conn=pymysql.connect(
                        host='localhost',
                        user='root',
                        password='cl19970312',
                        db='educationmanagersysterm',
                        charset='utf8',)
        print('            数据库连接成功')
    except pymysql.Error as e:
        print('            数据库连接失败',e)
    finally:
        while True:
            cur=conn.cursor()
            zhuce_login=input(index).strip()
            #1为登陆
            if zhuce_login=='1':
                user_mas=input(login).strip().split()
                user_id,user_password=user_mas[0],user_mas[1]
                #校验登陆
                sql='select * from login_student where sno="{}";'.format(user_id)
                #print(sql)
                cur.execute(sql)
                results=cur.fetchall()
                is_login=login_student(results,user_password)
                #登陆成功
                if is_login:
                    print("            登陆成功")
                    #处理数据
                    if  not handle_mas(user_id,cur):
                        continue
                else:
                    print("            用户名密码错误!即将返回返回首页")
                    continue
            #2为注册
            elif zhuce_login=='2':
                zhuce_mas(cur)
            #任意键退出
            else:
                print('            您已安全退出')
                break
        conn.commit()
        # 关闭游标
        cur.close()
        # 关闭连接
        conn.close()
if __name__=='__main__':
    main()

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
实现功能:
1.学生信息管理系统的增删改查
2.异常处理

如果对我的文章感兴趣,请为我点一个赞,如果有python的知识需要了解或探讨,可以加本人微信:cuiliang1666457052

  • 32
    点赞
  • 86
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 15
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 15
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

穆穆Max

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值