# -*- coding:utf-8 -*-
import sqlite3
#import tabulate
cn = sqlite3.connect("cust.db")
cur = cn.cursor()
def helpc():
print("请按照提示信息进行操作!")
print("程序设计:")
print("2012年6月2日")
print("客户管理系统,Ver 1.0 b")
return
def disp():
cur.execute('select * from ct')
users = cur.fetchall()
print(users)
table_header = ["CID","CNAME"]
print(tabulate.tabulate(users,header = table_header,tablefmt = 'grid'))
return
def delall():
cur,execute('drop table if exists ct')
cur.execute('create table ct(cid text(6) primary key,cname text(10))')
print("客户全部清空!")
return
def find(id):
cur.execute('select * from ct where cid=?',(id,))
users = cur.fetchall()
if len(users) > 0:
n = 1
else:
n = -1
return n
def appe():
id = input("请输入客户号:")
if id == '':
print("客户号无效!")
else:
if find(id) == 1:
print("客户已经存在!请重新添加!")
else:
name = input("请输入客户姓名:")
if name == '':
print("客户姓名无效!")
else:
cur.execute('insert into ct(cid,cname) values(?,?)',(id,name))
cn.commit()
print("添加成功!")
return
def seek():
id = input("请输入要查询的客户号:")
if find(id) == -1:
print("查无此人!")
else:
cur.execute('select * from ct where cid=?',(id,))
user = cur.fetchone()
print("客户号:{},客户姓名:{}".format(user[0],user[1]))
return
def dele():
id = input("请输入要删除客户的客户号:")
if find(id) == -1:
print("查无此人,无法实现删除!")
else:
print("客户号:;{}".format(id))
yn = input("确但要删除客户吗?(y/n)")
if yn == 'y':
cur.execute('delete from ct where cid=?',(id,))
cn.commit()
print("已经成功删除:{} 客户!".format(id))
else:
print("没有删除:{} 客户!".format(id))
return
def alter():
id = input("请输入需要修改客户的客户号:")
if find(id) == -1:
print("查无此人,无法实现修改!")
else:
print("原客户号:{}".format(id))
nid = input("请输入新客户号:")
if nid == '':
print("客户号无效!")
else:
if find(nid) == 1:
print("客户已经存在,请重新添加!")
else:
name = input("请输入新客户姓名:")
if name == '':
print("客户姓名无效!")
else:
cur.execute('update ct set cid=?,cname=? where cid=?',(nid,name,id))
cn.commit()
print("添加成功!")
while 1:
print("客户管理系统")
print("===========")
print("1.添加客户")
print("2.修改客户")
print("3.删除客户")
print("4.查询客户")
print("5.显示客户")
print("6.清空客户")
print("7.帮助信息")
print("8.退出系统")
yn = input("选择输入(1,2,3,4,5,6,7,8):")
if yn == '1':
appe()
elif yn == '2':
alter()
elif yn == '3':
dele()
elif yn == '4':
seek()
elif yn == '5':
disp()
elif yn == '6':
delall()
elif yn == '7':
helpc()
elif yn == '8':
print("谢谢使用,再见!")
cn.close()
break
else:
print("输入有误!")
input("回车继续")
求问为什么运行后无法添加客户
报错:Traceback (most recent call last):
File "E:\Python\python练习\数据库.py", line 115, in <module>
appe()
File "E:\Python\python练习\数据库.py", line 44, in appe
if find(id) == 1:
File "E:\Python\python练习\数据库.py", line 31, in find
cur.execute('select * from ct where cid=?',(id,))
sqlite3.OperationalError: no such table: ct
你还没创建数据库ct,你用数据库可视化工具(Navicat Premium 15)连接sqlite3,创建一个ct数据库就行了
Traceback (most recent call last):
File "E:\Python\python练习\数据库.py", line 124, in <module>
disp()
File "E:\Python\python练习\数据库.py", line 21, in disp
print(tabulate.tabulate(users,header = table_header,tablefmt = 'grid'))
TypeError: tabulate() got an unexpected keyword argument 'header'
老师请问这段是什么意思
您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632