资源简介
python+sqlite实现简单的学生成绩管理。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
代码片段和文件信息
# -*- coding: UTF-8 -*-
#__author__ = ‘fourier‘
# -*- coding: UTF-8 -*-
#__author__ = ‘fourier‘
import sqlite3
# conn = sqlite3.connect(‘test02.db‘)
# c = conn.cursor()
# c.execute(‘‘‘CREATE TABLE STUDENT
# (NAME TEXT PRIMARY KEY NOT NULL
# NUMBER INT NOT NULL
# GRADE INT NOT NULL);‘‘‘)
# print(“Table created successfully“)
# conn.commit()
# conn.close()
while(1):
code = input(“请输入操作代号,insert代表插入,select代表查询 delete代表删除exit代表退出\n“)
if code == ‘insert‘:
code_name = input(“请输入姓名:\n“)
code_number = input(“请输入学号:\n“)
code_grade = input(“请输入成绩:\n“)
conn1 = sqlite3.connect(‘test02.db‘)
c1 = conn1.cursor()
# c.execute(“INSERT INTO COMPANY (NAMEAGE) \
# VALUES (‘Paul‘ 32)“);
c1.execute(“INSERT INTO STUDENT (NAMENUMBERGRADE) VALUES (:st_code_name :st_code_number:st_code_grade)“{‘st_code_name‘:code_name ‘st_code_number‘:code_number‘st_code_grade‘:code_grade});
conn1.commit()
print (“insert successfully\n“)
conn1.close()
if code == ‘select‘:
print(‘所有学生信息如下:\n‘)
conn2 = sqlite3.connect(‘test02.db‘)
c2 = conn2.cursor()
cursor = c2.execute(“SELECT * from STUDENT“)
for row in cursor:
print (“NAME = “ row[0])
print(“NUMBER = “ row[1])
print (“GRADE = “ row[2]“\n“)
conn2.close()
select_name = input(“请输入需要查询的姓名:\n“)
conn3 = sqlite3.connect(‘test02.db‘)
c3 = conn3.cursor()
cursor = c3.execute(“SELECT * from STUDENT WHERE NAME = :st_name “{‘st_name‘:select_name})
for row in cursor:
print(“NAME = “ row[0])
print(“NUMBER = “ row[1])
print(“GRADE = “ row[2] “\n“)
print(‘select successful\n‘)
conn3.close()
if code == ‘delete‘:
delete_name = input(“请输入需要删除的姓名:\n“)
conn4 = sqlite3.connect(‘test02.db‘)
c4 = conn4.cursor()
cursor = c4.execute(“DELETE from STUDENT WHERE NAME = :st_name “{‘st_name‘:delete_name})
conn4.commit()
print(‘delete successful\n‘)
conn4.close()
if code == ‘exit‘:
break
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 51760 2018-04-29 11:39 学生成绩管理\1710080808张三Python实验二.docx
文件 2455 2018-04-29 11:38 学生成绩管理\sqlite_test02.py
文件 12288 2018-04-29 11:27 学生成绩管理\test02.db
目录 0 2018-04-29 11:40 学生成绩管理
----------- --------- ---------- ----- ----
66503 4
- 上一篇:Python手势识别与控制源码
- 下一篇:保存图片为 mnist格式
评论
共有 条评论