I am working on a Python quiz project in which the user answers a series of 10 mathematical questions. Their score/10 is stored in a SQLite database, in a row, along with their name.
I want to make it so that the row with their name can store that particular users last 5 scores, rather than 1 score.
I already have the score1 - score5 columns present with the table, but I am unsure how to specify which field the data should be added to.
I suspected it might be done with some sort of if statement:
If name is in RESULTS_TABLE; If score2 IS NULL Insert score into score2 Elif score3 IS NULL Insert score into score3 Elif score4 IS NULL Insert score into score4 Elif score5 IS NULL Insert score into score5 Else Overwrite score into score1 Else Insert into RESULTS_TABLE, name, class, score1
Obviously this pseudo-code isn't correct as SQLite doesn't have an 'if statement'. How would I go about coding this into my Python program so that the last 5 scores can be stored in my SQLite database?
Aucun commentaire:
Enregistrer un commentaire