MCPcopy Create free account
hub / github.com/Mrinank-Bhowmick/python-beginner-projects / create_database

Function create_database

projects/Quiz Game/setup_db.py:4–27  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2
3
4def 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
30if __name__ == "__main__":

Callers 1

setup_db.pyFile · 0.85

Calls 1

executeMethod · 0.45

Tested by

no test coverage detected