帮我检查代码import mysql.connector new={} from ks的编写 import kss def d(): mydb = mysql.connector.connect( host="localhost", user="root", passwd="wangzijiao2003" ) b=(input("请输入你的代号,代号请用数字书写")) e=b.isdigit() while True: if e==True: cc=int(b) print("创建成功") break else: print("创建失败") continue while True: passwd1=input("请输入你的密钥,注(密钥必须包含大小写字母)") a=passwd1.isupper()#大写 b=passwd1.islower()#小写 c=passwd1.isalpha()#字母 if (a==False)and(b==False)and(c==True): print("密钥保存成功") break else: print("仔细阅读") continue new[cc]=passwd1 if cc in new: print("ok,完成初始化") else: print("no") print("注册成功") print(new) for i1 in new.keys(): print("你的账号为") print(i1) for ii1 in new.values(): print("你的密码为") print(ii1) ass=mydb.cursor() ass.execute("show databases") for kkss in ass: print(kkss) ass.execute("use myku") ass.execute("CREATE TABLE IF NOT EXISTS zhanghu1 (id int NOT NULL AUTO_INCREMENT,root1 varchar(255) NULL,passwd1 varchar(255) NULL,PRIMARY KEY (id))") ass.execute("insert into zhanghu(id,root1,passwd1) values('{}','{}')".format(b,passwd1) mydb.commit() print("over")
时间: 2023-12-10 15:02:19 浏览: 30
你的代码有一些错误,这里给你修改一下:
```python
import mysql.connector
new = {}
def d():
mydb = mysql.connector.connect(
host="localhost",
user="root",
passwd="wangzijiao2003",
database="myku"
)
while True:
b = input("请输入你的代号,代号请用数字书写")
if b.isdigit():
cc = int(b)
print("创建成功")
break
else:
print("创建失败,请重新输入")
continue
while True:
passwd1 = input("请输入你的密钥,注(密钥必须包含大小写字母)")
if any(x.isupper() for x in passwd1) and any(x.islower() for x in passwd1):
print("密钥保存成功")
break
else:
print("密钥必须包含大小写字母,请重新输入")
continue
new[cc] = passwd1
if cc in new:
print("ok,完成初始化")
else:
print("no")
print("注册成功")
print(new)
for i1 in new.keys():
print("你的账号为")
print(i1)
for ii1 in new.values():
print("你的密码为")
print(ii1)
ass = mydb.cursor()
ass.execute("CREATE TABLE IF NOT EXISTS zhanghu1 (id int NOT NULL AUTO_INCREMENT,root1 varchar(255) NULL,passwd1 varchar(255) NULL,PRIMARY KEY (id))")
ass.execute("insert into zhanghu1(root1, passwd1) values('{}', '{}')".format(cc, passwd1))
mydb.commit()
print("over")
d()
```
主要修改如下:
1. 加入 `database="myku"` 以连接到指定的数据库;
2. 在密码检查时,使用 `any` 函数来检查大小写字母是否都存在;
3. 在插入数据时,修改表名为 `zhanghu1`,并修正 SQL 语句中的字段名和占位符。