0% found this document useful (0 votes)
9 views30 pages

Class12 Cs Project

Uploaded by

Kunal Singh
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)
9 views30 pages

Class12 Cs Project

Uploaded by

Kunal Singh
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/ 30

CONTENTS

S no. Topic Page No. Remarks

1. Cer ficate 03

2. ACKNOWLEDGEMENT 04

3. INTRODUCTION 05

4. MYSQL DATABASE 06

5. MYSQL connec vity 07

6. Func ons used 08

7. Python script 09-24

8. Outputs 25-29

9. Bibliography 30

1|Page
DL DAV MODEL SCHOOL, SHALIMAR BAGH

FOOTBALL CLUB MANAGEMENT


SYSTEM

PROJECT
FILE
SUBMITTED BY: DAKSH SINGH & RISHIT
AGGARWAL
CLASS: XII-A
ROLL NO: 06 & 21
SUBMITTED TO: Mrs. SEEMA BHATIA MAM
[PGT COMPUTER SCIENCE ]
2|Page
CERTIFICATE
This is to cer fy that Daksh Singh and Rishit
Aggarwal of class XII-A
(PCM) of DLDAV MODEL SCHOOL has done his
project on the Football club Management
system under my supervision. He has taken
interest and shown utmost sincerity in
comple ng this project.

I cer fy that this Project meets my


expecta ons and is per the guidelines issued
by CBSE, NEW DELHI.

Internal Examiner External Examiner

3|Page
ACKNOWLEDGEMENT
It is with pleasure that I acknowledge my sincere
gra tude to our teacher, Ms. Seema Bha a who taught
and undertook the responsibility of teaching the subject
computer science. We have greatly benefited from her
classes.
My sincere thanks go to our Principal, Ms. Reena
Rajpal who has always been a source of encouragement
and support and without whose inspira on, this project

would not have been successful.

Finally, I would like to express my sincere apprecia on


for all the other students in my batch, their friendship &

the fine mes that we all shared.


Last but not least, I would like to thank all those who
have helped directly or indirectly towards the
comple on of this project.

Daksh Singh and Rishit Aggarwal


XII A(PCM)

4|Page
INTRODUCTION
The Football Club Management System is a
simple and effec ve so ware tool designed to
help football clubs manage their players and
track their performance. This project is
especially useful for small to medium-sized
football clubs, providing an easy way to
handle important data like player details,
matches played, goals scored, and assists
made.
The system is built using Python for its
programming logic and MySQL for storing and
organizing data. It ensures that all informa on
is stored securely and can be easily accessed
or updated whenever needed. By combining
Python and MySQL, this project creates a
prac cal and user-friendly solu on for
football club management.

5|Page
CREATE DATABASE:
CREATE DATABASE football_club ;
USE football_club;
Crea ng playrs table:
The players table has three columns, which are
playerid, playername, playerposi on .
Create table players(
Playerid int() primary key ,
Playername varchar(30) not null ,
Playerposi on varchar(20) not null
);
Crea ng performance table:
The performance table has four columns, which are
playerid, matches, goals, assist .
Create table performance(
Playerid int() primary key ,
Matches int() ,
Goals int() ,
Assist int()
);

6|Page
Ge ng Started:
We need to make a connec on between the
MySQL database and Python so that the
tables can be accessed using python IDLE. For
making a connec on we need to install mysql-
connector which can be done by wri ng the
following command in the command prompt
on Windows. pip install mysql-connector-
python A er installa on of the mysql-
connector, we can connect MySQL with
Python which can be done by wri ng the
following code.
# Impor ng mysql connector module
import mysql.connector
# Making MySQLconnec on object
conn = mysql.connector.connect(
host='localhost', user='root',
password='password', database='football_club')
# Making MySQLcursor object cursor =
conn.cursor()

7|Page
Func ons used in the program:

1. Add player func on:


This func on is used to add players with the
help of their Name, posi on, and system-
automated ID.

2. Update player details func on:


This func on is being used to update player
details like their Name, and posi on.

3. Update Player Performance func on:


This func on is being used to update player
stats like the number of matches played, no of
goals scored, no of assists.

4. Delete Player func on:


This func on is used to delete players from
the club records.
5. View Players func on:
This func on is used to show all players details
like name, posi on, played, goal and assist,

8|Page
MainProgram:
The program first asks for a choice of the
manager to call the respec ve func ons for
the func oning of the program.
CompleteProjectCode:
import mysql.connector

# Func on to connect to the database


def connect_to_db():
try:
return mysql.connector.connect(
host="localhost",
user="root",
password="12345678",
database="football_club"
)
except mysql.connector.Error as err:

9|Page
print(f"Error connec ng to the database:
{err}")
return None

# Func on to ini alize the database and


create tables if they don't exist
def ini alize_database():
db = connect_to_db()
if not db:
return

try:
cursor = db.cursor()

# Create players table


cursor.execute("""
CREATE TABLE IF NOT EXISTS players (

10 | P a g e
playerid INT AUTO_INCREMENT
PRIMARY KEY,
playername VARCHAR(255) NOT
NULL,
playerposi on VARCHAR(255) NOT
NULL
)
""")

# Create performance table


cursor.execute("""
CREATE TABLE IF NOT EXISTS
performance (
playerid INT PRIMARY KEY,
matches INT DEFAULT 0,
goals INT DEFAULT 0,
assist INT DEFAULT 0,

11 | P a g e
FOREIGN KEY (playerid) REFERENCES
players(playerid) ON DELETE CASCADE
)
""")

print("Database ini alized and tables


created (if they did not exist).")
except mysql.connector.Error as err:
print(f"Error ini alizing database: {err}")
finally:
if db.is_connected():
db.close()

# Func on to add a new player


def add_player(playername, playerposi on):
db = connect_to_db()
if not db:
return
12 | P a g e
try:
cursor = db.cursor()
cursor.execute("""
INSERT INTO players (playername,
playerposi on)
VALUES (%s, %s)
""", (playername, playerposi on))
db.commit()

player_id = cursor.lastrowid
print(f"Player added with ID: {player_id}")

cursor.execute("INSERT INTO
performance (playerid) VALUES (%s)",
(player_id,))
db.commit()

except mysql.connector.Error as err:


13 | P a g e
print(f"Database error: {err}")
finally:
if db.is_connected():
db.close()

# Func on to update player details


def update_player_details(playerid,
playername, playerposi on):
db = connect_to_db()
if not db:
return
try:
cursor = db.cursor()
cursor.execute("""
UPDATE players
SET playername = %s, playerposi on =
%s
WHERE playerid = %s
14 | P a g e
""", (playername, playerposi on,
playerid))
db.commit()

if cursor.rowcount > 0:
print("Player details updated
successfully.")
else:
print("No player found with the given
ID.")

except mysql.connector.Error as err:


print(f"Database error: {err}")
finally:
if db.is_connected():
db.close()

# Func on to update player performance


15 | P a g e
def update_performance(playerid, matches,
goals, assists):
db = connect_to_db()
if not db:
return
try:
cursor = db.cursor()
cursor.execute("""
UPDATE performance
SET matches = %s, goals = %s, assist =
%s
WHERE playerid = %s
""", (matches, goals, assists, playerid))
db.commit()

if cursor.rowcount > 0:
print("Performance updated
successfully.")
16 | P a g e
else:
print("No player found with the given
ID.")

except mysql.connector.Error as err:


print(f"Database error: {err}")
finally:
if db.is_connected():
db.close()

# Func on to delete a player


def delete_player(playerid):
db = connect_to_db()
if not db:
return
try:
cursor = db.cursor()

17 | P a g e
cursor.execute("DELETE FROM players
WHERE playerid = %s", (playerid,))
db.commit()

if cursor.rowcount > 0:
print("Player deleted successfully.")
else:
print("No player found with the given
ID.")

except mysql.connector.Error as err:


print(f"Database error: {err}")
finally:
if db.is_connected():
db.close()

# Func on to view all players and their


performance
18 | P a g e
def view_players():
db = connect_to_db()
if not db:
return
try:
cursor = db.cursor()
cursor.execute("""
SELECT p.playerid, p.playername,
p.playerposi on, pr.matches, pr.goals, pr.assist
FROM players p
LEFT JOIN performance pr ON
p.playerid = pr.playerid
""")
players = cursor.fetchall()

print("\nPlayer Details:")
print("ID | Name | Posi on |
Matches | Goals | Assists")
19 | P a g e
print("-" * 60)
for player in players:
print(f"{player[0]:<3} | {player[1]:<10}
| {player[2]:<15} | {player[3]:<7} |
{player[4]:<5} | {player[5]:<6}")

except mysql.connector.Error as err:


print(f"Database error: {err}")
finally:
if db.is_connected():
db.close()

# Main menu func on


def main_menu():
while True:
print("\nFootball Club Management
System")
print("1. Add Player")
20 | P a g e
print("2. Update Player Details")
print("3. Update Player Performance")
print("4. Delete Player")
print("5. View Players")
print("6. Exit")
choice = input("Enter your choice: ")

if choice == '1':
playername = input("Enter player
name: ").strip()
playerposi on = input("Enter player
posi on: ").strip()
if playername and playerposi on:
add_player(playername,
playerposi on)
else:
print("Player name and posi on
cannot be empty.")

21 | P a g e
elif choice == '2':
try:
playerid = int(input("Enter player ID
to update details: "))
playername = input("Enter new
player name: ").strip()
playerposi on = input("Enter new
player posi on: ").strip()
if playername and playerposi on:
update_player_details(playerid,
playername, playerposi on)
else:
print("Player name and posi on
cannot be empty.")
except ValueError:
print("Invalid input. Please enter
numeric values for ID.")
elif choice == '3':
try:
22 | P a g e
playerid = int(input("Enter player ID
to update performance: "))
matches = int(input("Enter updated
matches played: "))
goals = int(input("Enter updated
goals scored: "))
assists = int(input("Enter updated
assists: "))
update_performance(playerid,
matches, goals, assists)
except ValueError:
print("Invalid input. Please enter
numeric values.")
elif choice == '4':
try:
playerid = int(input("Enter player ID
to delete: "))
delete_player(playerid)
except ValueError:
23 | P a g e
print("Invalid input. Please enter a
valid numeric ID.")
elif choice == '5':
view_players()
elif choice == '6':
print("Goodbye!")
break
else:
print("Invalid choice. Try again.")

# Call func ons directly to start the program


ini alize_database()
main_menu()

24 | P a g e
OUTPUTS:
 CHOICE1:

25 | P a g e
 CHOICE2:

26 | P a g e
 CHOICE3:

27 | P a g e
 CHOICE4:

28 | P a g e
 CHOICE5:

29 | P a g e
BIBLIOGRAPHY
1. www.w3schols.org\python3 (syntax)

2. NCERT TEXTBOOK Computer Science


(learning resource)

30 | P a g e

You might also like