python&的语法错误sqlite3的

时间:2014-11-02 11:01:13

标签: python sqlite

我在下面代码的最后一行使用sqlite3和Python有一个语法问题:

    playerName = input("Enter your name: ")
    money = input("Enter credits: ")
    conn = sqlite3.connect("highscore.db")
    c = conn.cursor()
    c.execute("CREATE TABLE players(name TEXT, money INTEGER)")
    c.execute("INSERT INTO players VALUES('%s','%s')", playerName, money)

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

更改此行:

c.execute("INSERT INTO players VALUES('%s','%s')", playerName, money)

要:

c.execute("INSERT INTO players VALUES(?,?);",(playerName, money))