| 2 | |
| 3 | |
| 4 | def create_database(): |
| 5 | # Connect to the SQLite database (it will create the file if it doesn't exist) |
| 6 | conn = sqlite3.connect("quiz_game.db") |
| 7 | |
| 8 | # Create a cursor object |
| 9 | cursor = conn.cursor() |
| 10 | |
| 11 | # Create a table to store players' scores |
| 12 | cursor.execute( |
| 13 | """ |
| 14 | CREATE TABLE IF NOT EXISTS scores ( |
| 15 | id INTEGER PRIMARY KEY AUTOINCREMENT, |
| 16 | name TEXT NOT NULL, |
| 17 | score INTEGER NOT NULL, |
| 18 | timestamp DATETIME DEFAULT CURRENT_TIMESTAMP |
| 19 | ) |
| 20 | """ |
| 21 | ) |
| 22 | |
| 23 | # Commit the changes and close the connection |
| 24 | conn.commit() |
| 25 | conn.close() |
| 26 | |
| 27 | print("Database and table created successfully.") |
| 28 | |
| 29 | |
| 30 | if __name__ == "__main__": |