1

New to coding - I've made a colour game so the user can get as many points as possible under a set time. I am trying to insert the scores into a table.

global score
global timeleft
if timeleft > 0:
    e.focus_set()
    if e.get().lower() == colours[1].lower():
        score += 1
    e.delete(0, Tkinter.END)
    random.shuffle(colours)
    label.config(fg = str(colours[1]), text = str(colours[0]))
    scoreLabel.config(text = "Score: " + str(score))

this is what i've tried so far for the data entry:

con=sqlite3.connect("winners.db")
cur= con.cursor()

def create_table():
    cur.execute("CREATE TABLE IF NOT EXISTS winners(user TEXT,")

def data_entry():
    cur.execute("INSERT INTO winners VALUES('User',")
    con.commit()
    cur.close()
    con.close()

#create_table()
data_entry()

I'm trying to get two columns of Users and Scores.

Please let me know if something isn't clear.

2 Answers2

0

Works for me, in Java, doing like this:

INSERT INTO winners VALUES('User',\"?\"")

or,

INSERT INTO winners VALUES('User','?'")
Meraj al Maksud
  • 1,528
  • 2
  • 22
  • 36
Pedro
  • 41
  • 1
  • 2
  • 8
  • Sorry I've confused you. the question mark was not meant to be a part of the code. I was only marking where I am stuck on. –  Aug 26 '19 at 02:03
  • You can create a variable with the query and concatenate the text that you want to insert. Read more about concatenation in python [here](https://stackoverflow.com/questions/53236784/efficient-string-concatenation-in-python-3) – Pedro Aug 26 '19 at 02:14
0
cur.execute("CREATE TABLE IF NOT EXISTS winners(user TEXT,")
cur.execute("INSERT INTO winners VALUES('User',")

You have created user , but you are trying to add scores to User

Try to make them both start with capital letter