21262174 余星舟 女 18 21大数据1班 大数据应用与技术 人工智能与大数据学院
21262175 肖琪锋 男 18 2021级软件2班 软件技术 人工智能与大数据学院
21262176 李鑫林 女 18 2021级软件3班 软件技术 人工智能与大数据学院
21262177 王春元 男 19 2021级数据1班 大数据应用与技术 人工智能与大数据学院
21262178 邓安杰 男 19 2021级软件3班 软件技术 人工智能与大数据学院
21262179 叶心仪 女 19 2021级软件3班 软件技术 人工智能与大数据学院
21262180 尹驰宇 男 19 21软件3班 软件技术 信息工程学院
'''
function:StudentsInformationManageSystem
author:Sherry
Time:2021.12.26
'''
import pymysql
#定义数据库链接参数
host = '127.0.0.1' #或者用local host
port = 3306
db = 'student'
user = 'root'
password = '111111'
conn = pymysql.connect(host=host, port=port, db=db, user=user, password=password)
def non():
cursor = conn.cursor(pymysql.cursors.SSCursor) #流式游标,默认返回元组
return cursor
#插入学生记录
def add_student():
cursor = non()
id = int(input('学号:'))
name = input('姓名:')
genden = input('性别:')
age = int(input('年龄:'))
garden = str(input('班级:'))
major = input('专业:')
college = input('学院:')
add = cursor.execute("insert into stu (id, name, genden, age, class, major, college)\
values(%s, %s, %s, %s, %s, %s, %s)", (id, name, genden, age, garden, major, college))
if add == 1:
conn.commit()
print('插入成功!')
else:
print('插入失败!')
#按学号查询
def Q_by_id():
cursor = non()
choose_id = int(input('请输入学号:'))
cursor.execute('select * from stu where id =%s', (choose_id))
student = cursor.fetchall()
for student in student:
print('{}\t{}\t{}\t{}\t{}\t{}\t{}' .format(student[0], student[1], student[2], student[3], student[4], student[5], student[6]))
re = input('\n是否继续查询y/n:')
if re == 'y':
Q_by_id()
else:
query_student()
#按姓名查询(以防学号输入错误)
def Q_by_name():
cursor = non()
choose_name = input('请输入姓名:')
cursor.execute('select * from stu where name =%s', (choose_name))
students = cursor.fetchall()
for student in students:
print('{}\t{}\t{}\t{}\t{}\t{}\t{}' .format(student[0], student[1], student[2], student[3], student[4], student[5], student[6]))
re = input('\n是否继续查询y/n:')
if re == 'y':
Q_by_name()
else:
query_student()
#查询所有学生
def Q_all():
cursor = non()
cursor.execute('select * from stu')
students = cursor.fetchall()
for student in students:
print('{}\t{}\t{}\t{}\t{}\t{}\t{}' .format(student[0], student[1], student[2], student[3], student[4], student[5], student[6]))
#查询的菜单
def query_student():
while True:
print('查询学生记录')
print('================')
print('1、按学号查询学生记录')
print('2、按姓名查询学生记录')
print('3、查询全部学生记录')
print('4、返回上级菜单')
print('=================')
mc3 = int(input('请输入菜单号:'))
if mc3 == 1:
Q_by_id()
elif mc3 == 2:
Q_by_name()
elif mc3 == 3:
Q_all()
else:
break
#删除学生记录
def D_student():
cursor = non()
id = int(input('输入想要删除学生的学号:'))
affect = cursor.execute('delete from stu where id = %s', (id))
if affect == 1:
conn.commit()
print('删除成功!')
else:
print('删除失败!')
#删除的菜单
def delete_student():
print('============================')
print('1、删除学生信息')
print('2、回到上一级菜单')
print('============================')
mc4 = int(input('Input menu number:'))
if mc4 == 1:
D_student()
elif mc4 == 2:
login()
#修改字段值
def modify_student():
cursor = non()
ID = int(input('请输入想要修改学生的学号:'))
cursor.execute('select * from stu where id = %s', (ID))
if cursor.fetchall() == []:
print('未查找到学号是{}的学生'.format(ID))
mc3 = input('是否重新查询?y/n')
if mc3 == 'y':
modify_student()
else:
login()
else:
print('==============')
print('1、修改姓名')
print('2、修改性别')
print('3、修改年龄')
print('4、修改班级')
print('5、修改专业')
print('6、修改学院')
print('7、返回上级菜单')
print('==============')
mc2 = int(input('请输入菜单号:'))
if mc2 == 1:
name = input('请输入修改后的值:')
a = cursor.execute('update stu set name = %s where id = %s', (name, ID))
if a > 1:
conn.commit()
print('修改成功!')
else:
print('修改失败!')
elif mc2 == 2:
sex = input('请输入修改后的值:')
a = cursor.execute('update stu set genden = %s where id = %s', (sex, ID))
if a > 1:
conn.commit()
print('修改成功!')
else:
print('修改失败!')
elif mc2 == 3:
age = int(input('请输入修改后的值:'))
a = cursor.execute('update stu set age = %s where id = %s', (age, ID))
if a > 1:
conn.commit()
print('修改成功!')
else:
print('修改失败!')
elif mc2 == 4:
garden = input('请输入修改后的值:')
a = cursor.execute('update stu set class = %s where id = %s', (garden, ID))
if a > 1:
conn.commit()
print('修改成功!')
else:
print('修改失败!')
elif mc2 == 5:
major = input('请输入修改后的值:')
a = cursor.execute('update stu set major = %s where id = %s', (major, ID))
if a > 1:
conn.commit()
print('修改成功!')
else:
print('修改失败!')
elif mc2 == 6:
college = input('请输入修改后的值:')
a = cursor.execute('update stu set college = %s where id = %s', (college, ID))
if a > 1:
conn.commit()
print('修改成功!')
else:
print('修改失败!')
else:
login()
#登入后的菜单----展开
def login():
while True:
print('学生管理系统')
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:
delete_student()
else:
break
#主程序
while True:
print('登录系统')
print('=========')
print('1、登录')
print('2、退出')
print('=========')
mc1 = int(input('输入菜单号:'))
if mc1 == 1:
username = input('请输入用户名:')
password = input('请输入密码:')
if username == 'admin' and password == '111111':
login()
else:
print('账号或密码错误!')
elif mc1 == 2:
print('感谢使用!')
break