import sqlite3

cx = sqlite3.connect('E:\\student3.db')

cx.execute( '''CREATE TABLE StudentTable(
ID INTEGER PRIMARY KEY AUTOINCREMENT,
StuId INTEGER NOT NULL,
NAME TEXT NOT NULL,
CLASS INT NOT NULL
);''') print("Table created successfully!")
Table created successfully!
cx.execute('''CREATE TABLE CourseTable  (
CourseId INT NOT NULL,
Name TEXT NOT NULL,
Teacher TEXT NOT NULL,
Classroom TEXT NOT NULL,
StartTime CHAR(11) NOT NULL,
EndTime CHAR(11) NOT NULL
);''') cu = cx.cursor() CourseTable = [('', 'Qt', 'ming', 602, 'Monday9:00', 'Monday11:00'),('', 'Linux', 'han', 605, 'Friday13:20', 'Friday14:20'),('', 'sqlite3', 'hah', 608, 'Thursday15:00', 'Thursday17:00')]
cu.executemany("insert into CourseTable values(?, ?, ?, ?, ?, ?)", CourseTable)
cx.commit()
print("Table created successfully!")
Table created successfully!
cx.execute('''CREATE TABLE XuankeTable(
ID INTEGER PRIMARY KEY AUTOINCREMENT,
StuId INT NOT NULL,
CourseId INT NOT NULL
);''') print("Table created successfully")
Table created successfully
def insert_stu():#插入学生信息
cu = cx.cursor()
stu_id = input("请输入学生学号:")
cu.execute("select StuId from StudentTable where StuId =%s" %(stu_id))
row = cu.fetchone()
if row:
print("Sorry,该学号已存在,请重新输入")
else:
stu_name = input("请输入学生姓名")
stu_class = input("请输入学生班级")
sql1 = "insert into StudentTable(StuId, NAME, CLASS) values(%s, '%s', %s);" % (stu_id, stu_name, stu_class)
cu.execute(sql1)
cx.commit()
print("恭喜你,学生录入成功!")
cu.close()
def xuanke():#学生选课
cu = cx.cursor()
stu_id = input("请输入要选课的学生学号:")
sql2 = "select StuId from StudentTable where StuId =%s"%(stu_id)
cu.execute(sql2)
row = cu.fetchone()
if row:
sql3 = "select CourseId, Name, Teacher, Classroom, StartTime, EndTime from CourseTable"
cu.execute(sql3)
rows = cu.fetchall()
for row in rows:
print("CourseId = ", row[0])
print("Name = ", row[1])
print("Teacher = ", row[2])
print("Classroom = ", row[3])
print("StartTime = ", row[4])
print("EndTime = ", row[5], "\n")
cou_id = input("请输入要选的课程号是:")
sql0 = "select CourseId from CourseTable where CourseId = %s"%(cou_id)
cu.execute(sql0)
row = cu.fetchone()
if row:
sql = "select StuId CourseId from XuankeTable where CourseId = %s and StuId = %s;" % (cou_id,stu_id)
cu.execute(sql)
row = cu.fetchone()
if row:
print("该课程已选,不能重复选课!")
else:
sqll = "insert into XuankeTable (stuId,CourseId) values (%s,%s);" % (stu_id,cou_id)
cu.execute(sqll)
cx.commit()
print("带喜你,选课成功!")
else:
print("Sorry,该课程不存在!")
else:
print("Sorry,没有该学生号!")
cu.close()
def stu_id_search():#通过学生Id,查询学生信息
cu = cx.cursor()
search_stu_id = input("请输入要查询的学号:")
sql4 = "select ID,StuId,NAME,CLASS from StudentTable where StuId=%s"%(search_stu_id)
cu.execute(sql4)
row = cu.fetchone()
cx.commit()
if row:
sql5 = "select ID,StuId,NAME,CLASS from StudentTable"
cu.execute(sql5)
rows = cu.fetchall()
for row in rows:
print("---------")
print("您要查询的学生信息为:")
print("ID=",row[0])
print("StuId",row[1])
print("NAME=",row[2])
print("CLASS = ",row[3],"\n")
else:
print("Sorry, 没有该学生信息!")
cu.close()
def stu_id_cou():#通过学生Id,查询学生Id的课程信息
cu = cx.cursor()
stu_id = input("请输入要查询学生号:")
sql5 = "select StuId from StudentTable where stuId =%s" % (stu_id)
cu.execute(sql5)
row = cu.fetchall()
if row:
sql6 = "select * from XuankeTable a left join CourseTable b on a.CourseId=b.CourseId"
cu.execute(sql6)
rows = cu.fetchall()
for row in rows:
print("该学生所选课程为:")
print("StuId = ",row[1])
print("CourseId = ",row[2])
print("Name = ", row[4])
print("Teacher = ", row[5])
print("Classroon =",row[6])
print("StartTime = ",row[7])
print("EndTime = ", row[8], "\n")
print("-----------------")
else:
print("sorry,没有该学生选课信息!")
cu.close()
def cou_id_serach():#通过课程Id,查询课程信息
cu = cx.cursor()
cou_id = input("请输入要查询的课程号:")
sql7 = "select CourseId,Name,Teacher,Classroom,StartTime,EndTime from CourseTable where CourseId =%s"%(cou_id)
cu.execute(sql7)
row = cu.fetchone()
if row:
print("您要查询的课程信息为:")
print("CourseId = ", row[0])
print("Name = ", row[1])
print("Teacher = ", row[2])
print("Classroom = ", row[3])
print("StartTime = ",row[4])
print("EndTime = ", row[5], "\n")
else:
print("Sorry,没有该课程信息!")
cu.close()
def cou_id_stu():#通过课程号查询所选学生信息
cu = cx.cursor()
cou_id = input("请输入课程号:")
sql8 = "select CourseId from XuankeTable where CourseId =%s" % (cou_id)
cu.execute(sql8)
row = cu.fetchone()
if row:
sql9 = "select * from XuankeTable a left join StudentTable b on a.StuId=b.StuId"
cu.execute(sql9)
rows = cu.fetchall()
for row in rows:
print("-----------------------------")
print("选择该课程的学生为:")
print("StuId = ", row[1])
print("NAME = ", row[5])
print("CLASS = ", row[6])
else:
print("Sorry,没有该课程信息!")
cu.close()
def menu():
print("1.进入学生信息系统(学生信息录入)")
print("2.进入学生选课系统(学生选课操作)")
print("3.进入学生选课信息系统(学生信息查询和选课情况查询)")
print("4.退出程序")
def student():
print("1.录入学生信息")
print("2.返回主菜单") def Course():
print("1.开始选课")
print("2.返回主菜单") def information():
print("1.按学号查询学生信息")
print("2.按学号查看学生选课课程列表")
print("3.按课程号查看课程信息")
print("4.按课程号查看选课学生列表")
print("5.返回主菜单")
while True:
menu()
print("---------------------")
x = input("请输入您的选择菜单号:")
if x == '':
student()
stu = input("您已进入学生录入系统,请再次输入选择菜单:")
print("---------------------")
if stu == '':
insert_stu()
continue
if stu == '':
continue
else:
print("输入的选项不存在,请重新输入!")
continue if x == '':
#进入造课信息系统
Course()
cou = input("您已进入学生选课系统,请再次输入选择菜单:")
print("------------------")
if cou == '':
xuanke()
continue
if cou == '':
continue
else:
print("输入的选项不存在,请重新输入!")
continue if x == '':
#进入学生选课信息表
information()
inf = input("您已进入学生选课信息系统,请再次输入选择菜单:")
print("------------------")
if inf == '':
stu_id_search()
continue
if inf == '':
stu_id_cou()
continue
if inf == '':
cou_id_serach()
continue
if inf == '':
cou_id_stu()
else:
print("输入的选项不存在,请重新输入!")
continue if x == '':
print("谢谢使用")
exit()
else:
print("输入的选项不存在,请重新输入!")
continue

吴裕雄--python学习笔记:sqlite3 模块的使用与学生信息管理系统的更多相关文章

  1. 吴裕雄--python学习笔记:sqlite3 模块

    1 sqlite3.connect(database [,timeout ,other optional arguments]) 该 API 打开一个到 SQLite 数据库文件 database 的 ...

  2. 吴裕雄--python学习笔记:通过sqlite3 进行文字界面学生管理

    import sqlite3 conn = sqlite3.connect('E:\\student.db') print("Opened database successfully&quo ...

  3. 吴裕雄--python学习笔记:os模块的使用

    在自动化测试中,经常需要查找操作文件,比如说查找配置文件(从而读取配置文件的信息),查找测试报告(从而发送测试报告邮件),经常要对大量文件和大量路径进行操作,这就依赖于os模块. 1.当前路径及路径下 ...

  4. 吴裕雄--python学习笔记:os模块函数

    os.sep:取代操作系统特定的路径分隔符 os.name:指示你正在使用的工作平台.比如对于Windows,它是'nt',而对于Linux/Unix用户,它是'posix'. os.getcwd:得 ...

  5. 吴裕雄--python学习笔记:BeautifulSoup模块

    import re import requests from bs4 import BeautifulSoup req_obj = requests.get('https://www.baidu.co ...

  6. 吴裕雄--python学习笔记:爬虫基础

    一.什么是爬虫 爬虫:一段自动抓取互联网信息的程序,从互联网上抓取对于我们有价值的信息. 二.Python爬虫架构 Python 爬虫架构主要由五个部分组成,分别是调度器.URL管理器.网页下载器.网 ...

  7. 吴裕雄--python学习笔记:爬虫包的更换

    python 3.x报错:No module named 'cookielib'或No module named 'urllib2' 1. ModuleNotFoundError: No module ...

  8. 吴裕雄--python学习笔记:爬虫

    import chardet import urllib.request page = urllib.request.urlopen('http://photo.sina.com.cn/') #打开网 ...

  9. Python学习笔记之模块与包

    一.模块 1.模块的概念 模块这一概念很大程度上是为了解决代码的可重用性而出现的,其实这一概念并没有多复杂,简单来说不过是一个后缀为 .py 的 Python 文件而已 例如,我在某个工作中经常需要打 ...

随机推荐

  1. WIFI无线协议802.11a/b/g/n/ac的演变以及区别

    摘自:https://blog.csdn.net/Brouce__Lee/article/details/80956945 毫无疑问,WiFi的出现普及带给我们巨大的上网便利,所以了解一下WiFi对应 ...

  2. Python dict 和 list 转换

    这里有个dict d1 = { 'en':'英语', 'cn':'中文', 'fr':'法语', 'jp':'日语' } 使用d1.keys()或 d1.values() 可以提取出values 和k ...

  3. 面向对象 part3 构造函数 原型函数

    6.2创建对象 方法:对象字面量  object构造函数 缺点:都是创建单个对象.同一个接口创建多个对象,会产生大量重复代码 6.2.1工厂模式 用函数封装以特定的接口创建对象 function cr ...

  4. 两个tomcat使用同一个jvm可能会出错

    如果两个tomcat中的项目的某些类具有完全相同的包路径和类名的话,jvm可能会“弄混”这两个类,所以一般要求包名“必须”唯一. 当然,如果两个类中的代码和import的类完全一样,弄混了也就弄混了, ...

  5. v-charts使用总结(随时补充)

    柱状图.折线图.环图的常用配置(配置连接地址https://v-charts.js.org/#/line) :data 绑定基本数据 { // 第一个参数为维度(就是横轴,例如时间),剩余为指标(就是 ...

  6. 10. 通过 Dockerfile 编写 linux 命令行工具

    测试 linux 压力的工具 一. 实际操作 1. 创建一个 ubuntu 的容器 docker run -it ubuntu 2. 安装 stress 工具 apt-get update & ...

  7. 吴裕雄--天生自然 PYTHON3开发学习:循环语句

    n = 100 sum = 0 counter = 1 while counter <= n: sum = sum + counter counter += 1 print("1 到 ...

  8. 树莓派切换到root用户

    1:如何修改pi账号密码 passwd pi 2:开启root账户 树莓派使用的linux是debian系统,所以树莓派启用root和debian是相同的 debian里root账户默认没有密码,但账 ...

  9. Educational Codeforces Round 68 差G

    Educational Codeforces Round 68 E 题意:有 n 个线段,每个都是平行 x 或者 y 轴,只有互相垂直的两线段才会相交.问形成了多少个矩形. \(n \le 5000, ...

  10. 900B. Position in Fraction#分数位置(模拟)

    题目出处:http://codeforces.com/problemset/problem/900/B 题目大意:找到一个数字在小数部分中第一次出现的位置 #include<iostream&g ...