Prt_sc_End
2020-06-17 21:19
采纳率: 75%
浏览 132

Python大佬们帮我看看

图片说明
报错:name 'falg' is not defined
import sqlite3
def opendb():
conn = sqlite3.connect("d:\mydb.db")
cue = conn.execute("""create table if not exists tongxunlu(usernum onteger primary kry,user name varchar(128),password varchar(128),address varcher(125),telnum varchar(128))""")
return cur,conn
def showalldb():
print("处理后的数据")
hel = opendb()
cur = hel[1].cursor()
cur.rxrcute("select * from tongxunlu")
res = cur.fetchall()
for lin in res:
for h in line:
print(h),
print
cur.close()
def into():
usernum = input("请输入学号")
username1 = input("请输入姓名")
password1 = input("请输入密码")
return usernum,username1,password1
def adddb():
welcome = """欢迎使用添加数据功能"""
print(welcome)
person = into()
hel = opendb()
hel[1].execute("insert into tongxunlu(usernum,username,password)values(?,?,?)",(person[0],person[1],person[2]))
hel[1].commit()
print("恭喜,添加数据成功")
showalldb()
hel[1].close()
def deldb():
welcome = "欢迎使用删除功能"
print(welcome)
delchoice = input("请输入想删除的学号")
hel = opendb()
hel[1].execute("delete from tongxunlu where username ="+delchoice)
hel[1].commit()
print("删除成功")
showalldb()
hel[1].close()
def alter():
welcome = "欢迎使用修改功能"
print(welcome)
changechoice = input("请输入学号")
hel = opendb()
person = into()
hel[1].execute("update tongxunlu set usernum = ?,username = ?,password = ? where usernum = "+ changechoice,(person[0],person[1],person[2]))
hel[1].commit()
showalldb()
hel[1].close()
def searchdb():
welcome = "欢迎使用查询功能"
print(welcome)
choice = input("请输入学号")
hel = opendb()
cur = hel[1].cursor()
cur.execute("select * from tongxunlu where usernum = "+ choice)
hel[1].commit()
print("数据如下")
for row in cur:
print(row[0],roe[1],row[2])
cur.close()
hel[1].close()
def conti(a):
choice = input("是否继续")
if choice == 'y':
a = 1
else:
a = 0
return a
if __name_ == "__main__":
flag = 1
while falg:
_
welcome = "欢迎使用数据库"
print(welcome)
choiceshow = """
请选择:
(添加)添加
(删除)删除
(修改)修改
(查询)查询
选择您的操作:
"""
choice = input(choiceshow)
if choice =="添加":
adddb()
conti(flag)
elif choice =="删除":
deldb()
conti(flag)
elif choice =="修改":
alter()
conti(flag)
elif choice =="查询":
searchdb()
conti(flag)
else:
print("输入错误")
print("请重新出入")

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • threenewbee 2020-06-17 23:40
    已采纳

    前面是fkag
    后面写成了 falg
    拼写错误

    问题解决的话,清点下采纳

    打赏 评论

相关推荐 更多相似问题