Python3代码不断收到错误“conn无法识别”

时间:2018-05-12 03:30:08

标签: python sqlite

import sqlite3


import random

a = input("what is your username?")

b = ("what is your password?")

c = random.randint(100000,999999)

database = sqlite3.connect("login_username.db")

x = conn.cursor()

x.execute("""Username text,
             Password text,
             Login id integer
             """)

conn.commit()

x.execute("INSERT INTO login_username VALUES (a, b ,c )")

conn.commit()

1 个答案:

答案 0 :(得分:1)

你的连接变量是错误的。代码应该是这样的:

import sqlite3

import random

a = input("what is your username?")

b = ("what is your password?")

c = random.randint(100000,999999)

database = sqlite3.connect("login_username.db")

x = database.cursor()

x.execute("""Username text, Password text, Login id integer """)

database.commit()

x.execute("INSERT INTO login_username VALUES (a, b ,c )")

database.commit()