完整代碼
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
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/241343.html
標籤:python
