最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python基于mysql實現(xiàn)學(xué)生管理系統(tǒng)

 更新時間:2021年08月12日 14:38:23   作者:qd_tudou  
這篇文章主要為大家詳細(xì)介紹了Python基于mysql實現(xiàn)學(xué)生管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本篇文章主要介紹了Python基于mysql實現(xiàn)學(xué)生管理系統(tǒng),分享給大家,具體如下:

import pymysql
import re
 
def idinput(string):
 ID = input(string)
 pattern = re.compile("^\d{1,3}$")
 while not re.match(pattern, ID):
  ID = input("請輸入1-3位整數(shù):")
 return ID
 
def appendStudentInfo():
 ID =idinput("請輸入學(xué)生學(xué)號:")
 db=pymysql.connect(host="127.0.0.1",user="root",passwd="hisense",db="test",port=3306,charset="utf8")
 cursor=db.cursor()
 sql = "select * from StuSys where ID = '%s'" % ID
 cursor.execute(sql)
 while cursor.rowcount > 0 :
  ID = idinput("該學(xué)號已存在,請重新輸入:")
  sql = "select * from StuSys where ID = '%d'" % int(ID)
  cursor.execute(sql)
 
 name=input("請輸入學(xué)生姓名:")
 
 chinese=input("請輸入語文成績:")
 while not chinese.isdigit() or int(chinese)>100 or int(chinese)<0:
  chinese = input("輸入錯誤,請重新輸入:")
 
 math =input("請輸入數(shù)學(xué)成績:")
 while not math.isdigit() or int(math) > 100 or int(math) < 0:
  math = input("輸入錯誤,請重新輸入:")
 
 english=input("請輸入英語成績:")
 while not english.isdigit() or int(english) > 100 or int(english) < 0:
  english = input("輸入錯誤,請重新輸入:")
 
 total=int(chinese)+int(math)+int(english)
 
 sql="""INSERT INTO StuSys(ID,
   NAME,CHINESE,ENGLISH,MATH,TOTAL)
   VALUES (%s,%s,%s,%s,%s,%s)"""
 cursor.execute(sql,(ID,name,chinese,english,math,total))
 db.commit()
 db.close()
 
def delstudent():
 delstudentid = idinput("請輸入要刪除的學(xué)生學(xué)號:")
 if querystudent(delstudentid):
  select = input("是否刪除:是(Y)/否(N)")
  if select == "Y" or select == "y":
   db = pymysql.connect(host="127.0.0.1", user="root", passwd="hisense", db="test", port=3306, charset="utf8")
   cursor = db.cursor()
   sql = "delete from stusys where ID =%s" %delstudentid
   cursor.execute(sql)
   db.commit()
   db.close()
   print("刪除成功")
  elif select == "N" or select == "n":
   print("取消刪除")
  else:
   print("輸入錯誤")
 
 
def querystudent(querystudentid):
 db=pymysql.connect(host="127.0.0.1",user="root",passwd="hisense",db="test",port=3306,charset="utf8")
 cursor=db.cursor()
 sql="select * from stusys where ID=%s"%querystudentid
 cursor.execute(sql)
 if cursor.rowcount ==0 :
  print("不存在該學(xué)生信息")
  return False
 else:
  print("該學(xué)生信息如下:")
  results =cursor.fetchall()
  print("ID=%d,NAME=%s,CHINESE=%d,ENGLISH=%d,MATH=%d,TOTAL=%d" % \
   (results[0][0], results[0][1], results[0][2], results[0][3], results[0][4],results[0][5]))
  return True
 
def modifystudentifo():
 modifyid = idinput("請輸入要的學(xué)生學(xué)號:")
 if querystudent(modifyid):
  name = input("請重新輸入學(xué)生姓名:")
 
  chinese = input("請重新輸入語文成績:")
  while not chinese.isdigit() or int(chinese) > 100 or int(chinese) < 0:
   chinese = input("輸入錯誤,請重新輸入:")
 
  math = input("請重新輸入數(shù)學(xué)成績:")
  while not math.isdigit() or int(math) > 100 or int(math) < 0:
   math = input("輸入錯誤,請重新輸入:")
 
  english = input("請重新輸入英語成績:")
  while not english.isdigit() or int(english) > 100 or int(english) < 0:
   english = input("輸入錯誤,請重新輸入:")
 
  total = int(chinese) + int(math) + int(english)
  db = pymysql.connect(host="127.0.0.1", user="root", passwd="hisense", db="test", port=3306, charset="utf8")
  cursor = db.cursor()
  sql1="update stusys set name ='%s' where id = %s"%(name,modifyid)
  cursor.execute(sql1)
  sql2="update stusys set math = %s where id = %s"%(math,modifyid)
  cursor.execute(sql2)
  sql3 = "update stusys set english = %s where id =%s"%(english,modifyid)
  cursor.execute(sql3)
  sql4 = "update stusys set total = %s where id = %s"%(total,modifyid)
  cursor.execute(sql4)
  sql5 = "update stusys set chinese = %s where id = %s"%(chinese,modifyid)
  cursor.execute(sql5)
  db.commit()
  db.close()
 
def allinfo():
 db=pymysql.connect(host="127.0.0.1",user="root",passwd="hisense",db="test",port=3306,charset="utf8")
 cursor=db.cursor()
 sql="select * from stusys"
 cursor.execute(sql)
 results= cursor.fetchall()
 for row in results:
  ID = row[0]
  NAME = row[1]
  CHINESE = row[2]
  ENGLISH = row[3]
  MATH = row[4]
  TOTAL = row[5]
  # 打印結(jié)果
  print("ID=%d,NAME=%s,CHINESE=%d,ENGLISH=%d,MATH=%d,TOTAL=%d" % \
    (ID, NAME, CHINESE, ENGLISH, MATH,TOTAL))
 
def studentMenu():
 print("="*30)
 print("學(xué)生管理系統(tǒng)")
 print("1、添加學(xué)生信息")
 print("2、刪除學(xué)生信息")
 print("3、查詢學(xué)生信息")
 print("4、修改學(xué)生信息")
 print("5、全部學(xué)生信息")
 print("6、退出")
 print("="*30)
 
 
 
if __name__ == '__main__':
 
 while True:
  studentMenu()
  menuindex = input("請輸入選項序號:")
  while not menuindex.isdigit():
   menuindex = input("輸入錯誤,請重新輸入:")
  if int(menuindex) ==1:
   appendStudentInfo()
  elif int(menuindex) ==2:
   delstudent()
  elif int(menuindex) ==3:
   querystudentid = idinput("請輸入要查詢的學(xué)生學(xué)號:")
   querystudent(querystudentid)
  elif int(menuindex) ==4:
    modifystudentifo()
  elif int(menuindex) == 5:
    allinfo()
  elif int(menuindex) == 6:
   break
  else:
   print("輸入序號無效")

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 淺談tensorflow之內(nèi)存暴漲問題

    淺談tensorflow之內(nèi)存暴漲問題

    今天小編就為大家分享一篇淺談tensorflow之內(nèi)存暴漲問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-02-02
  • 詳解Python中的Array模塊

    詳解Python中的Array模塊

    這篇文章主要介紹了詳解Python中的Array模塊,Python中的array模塊是一個預(yù)定義的數(shù)組,因此其在內(nèi)存中占用的空間比標(biāo)準(zhǔn)列表小得多,同時也可以執(zhí)行快速的元素級別操作,例如添加、刪除、索引和切片等操作,需要的朋友可以參考下
    2023-04-04
  • 如何實現(xiàn)刪除numpy.array中的行或列

    如何實現(xiàn)刪除numpy.array中的行或列

    如何實現(xiàn)刪除numpy.array中的行或列?今天小編就為大家分享一篇對刪除numpy.array中行或列的實例講解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-05-05
  • 正則化DropPath/drop_path用法示例(Python實現(xiàn))

    正則化DropPath/drop_path用法示例(Python實現(xiàn))

    DropPath 類似于Dropout,不同的是 Drop將深度學(xué)習(xí)模型中的多分支結(jié)構(gòu)隨機(jī)"失效",而Dropout是對神經(jīng)元隨機(jī)"失效"這篇文章主要給大家介紹了關(guān)于正則化DropPath/drop_path用法的相關(guān)資料,需要的朋友可以參考下
    2022-04-04
  • PyTorch 中的 torch.utils.data 解析(推薦)

    PyTorch 中的 torch.utils.data 解析(推薦)

    這篇文章主要介紹了PyTorch?torch.utils.data.Dataset概述案例詳解,主要介紹對?torch.utils.data.Dataset?的理解,需要的朋友可以參考下
    2023-02-02
  • OpenCV計算平均值cv::mean實例代碼

    OpenCV計算平均值cv::mean實例代碼

    函數(shù)cv::mean計算數(shù)組元素的平均值M,每個通道都是獨立的,并返回這個平均值,這篇文章主要給大家介紹了關(guān)于OpenCV計算平均值cv::mean的相關(guān)資料,需要的朋友可以參考下
    2021-08-08
  • 機(jī)器學(xué)習(xí)、深度學(xué)習(xí)和神經(jīng)網(wǎng)絡(luò)之間的區(qū)別和聯(lián)系

    機(jī)器學(xué)習(xí)、深度學(xué)習(xí)和神經(jīng)網(wǎng)絡(luò)之間的區(qū)別和聯(lián)系

    機(jī)器學(xué)習(xí)>神經(jīng)網(wǎng)絡(luò)>深度學(xué)習(xí)≈深度神經(jīng)網(wǎng)絡(luò),機(jī)器學(xué)習(xí)包括了神經(jīng)網(wǎng)絡(luò)在內(nèi)的許多算法,而神經(jīng)網(wǎng)絡(luò)又可以分為淺度神經(jīng)網(wǎng)絡(luò)和深度神經(jīng)網(wǎng)絡(luò),深度學(xué)習(xí)是使用了深度神經(jīng)網(wǎng)絡(luò)的技術(shù),雖然機(jī)器學(xué)習(xí)、深度學(xué)習(xí)和神經(jīng)網(wǎng)絡(luò)是不同的,但在構(gòu)建復(fù)雜系統(tǒng)時,許多相關(guān)概念是混合在一起的
    2024-02-02
  • python中hasattr方法示例詳解

    python中hasattr方法示例詳解

    hasattr()函數(shù)是Python中一個非常有用的工具,可以幫助我們在運(yùn)行時檢查對象的屬性或方法,通過合理地使用hasattr()函數(shù),我們可以寫出更靈活、可維護(hù)和健壯的代碼,這篇文章主要介紹了python中hasattr方法,需要的朋友可以參考下
    2023-12-12
  • Python基于PycURL自動處理cookie的方法

    Python基于PycURL自動處理cookie的方法

    這篇文章主要介紹了Python基于PycURL自動處理cookie的方法,實例分析了Python基于curl操作cookie的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-07-07
  • python數(shù)組中的?k-diff?數(shù)對例題解析

    python數(shù)組中的?k-diff?數(shù)對例題解析

    這篇文章主要介紹了python數(shù)組中的?k-diff?數(shù)對例題解析,文章根據(jù)題目內(nèi)容對其進(jìn)行分析以此展開主題內(nèi)容,感興趣的小伙伴可以參考一下下面文章詳情
    2022-06-06

最新評論

曲麻莱县| 石楼县| 珲春市| 平湖市| 深州市| 蒙自县| 丰都县| 满城县| 鄂托克旗| 株洲市| 石楼县| 宜黄县| 紫金县| 永和县| 七台河市| 大田县| 双辽市| 绍兴县| 伊金霍洛旗| 万宁市| 左云县| 冀州市| 吴旗县| 中江县| 永康市| 偏关县| 手游| 且末县| 新龙县| 闸北区| 陇南市| 咸丰县| 克拉玛依市| 扎鲁特旗| 安国市| 唐河县| 扬州市| 九龙县| 靖宇县| 全州县| 漠河县|