0% found this document useful (0 votes)
2 views3 pages

Class12 Python SQL Game Tracker Project

Uploaded by

alexvvs50
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Class12 Python SQL Game Tracker Project

Uploaded by

alexvvs50
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Class 12 Python + SQL Project

Game Release Database (2010 - Present)

Project Description:

This project combines Python and SQL to create a game release database system. Students can

add, view, search, and sort games released from the year 2010 onwards. The program uses SQLite

as the backend database and Python for the user interface.

Features:

- Create and connect to SQLite database

- Create a table for storing games

- Add a new game to the database

- Display all games

- Search games by release year

- Sort games alphabetically or by year

- Use SQL queries for data handling

Python + SQL Code:


import sqlite3

# Connect to database (or create it)


conn = sqlite3.connect("games.db")
cursor = conn.cursor()

# Create table if it doesn't exist


cursor.execute("""
CREATE TABLE IF NOT EXISTS games (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
year INTEGER NOT NULL CHECK(year >= 2010)
)
""")

# Function to add a new game


def add_game():
name = input("Enter game name: ")
year = int(input("Enter release year: "))
try:
cursor.execute("INSERT INTO games (name, year) VALUES (?, ?)", (name, year))
conn.commit()
print("Game added successfully!")
except:
print("Error: Year must be 2010 or later.")

# Function to view all games


def view_games():
cursor.execute("SELECT name, year FROM games")
rows = cursor.fetchall()
if rows:
print("\nGames List:")
for row in rows:
print(f"- {row[0]} ({row[1]})")
else:
print("No games found.")

# Function to search by year


def search_by_year():
year = int(input("Enter year to search: "))
cursor.execute("SELECT name FROM games WHERE year = ?", (year,))
games = cursor.fetchall()
if games:
print(f"Games released in {year}:")
for game in games:
print(f"- {game[0]}")
else:
print("No games found for this year.")

# Function to sort games


def sort_games():
print("1. Sort by Name\n2. Sort by Year")
choice = input("Enter choice: ")
if choice == "1":
cursor.execute("SELECT name, year FROM games ORDER BY name ASC")
elif choice == "2":
cursor.execute("SELECT name, year FROM games ORDER BY year ASC")
else:
print("Invalid choice")
return
sorted_games = cursor.fetchall()
print("Sorted Games:")
for game in sorted_games:
print(f"- {game[0]} ({game[1]})")

# Menu-driven interface
while True:
print("\n--- Game Release Tracker ---")
print("1. Add Game")
print("2. View All Games")
print("3. Search by Year")
print("4. Sort Games")
print("5. Exit")
choice = input("Enter choice: ")
if choice == "1":
add_game()
elif choice == "2":
view_games()
elif choice == "3":
search_by_year()
elif choice == "4":
sort_games()
elif choice == "5":
print("Goodbye!")
break
else:
print("Invalid input")

# Close the connection


conn.close()

You might also like