You are on page 1of 15

EXPENSE TRACKER

Computer Science (083)

Class XII - Science

Central Board of Secondary Education

By: Guided By:


Shria Shettigar Mrs. Krunali Prajapati

2023 – 2024

Senior Secondary Section

LAXMI INTERNATIONAL SCHOOL


LAXMI VIDYAPEETH
P.B. No. 15, SARIGAM P.O., VALSAD – 396 155 GUJARAT, INDIA

1|Page
LAXMI INTERNATIONAL SCHOOL
P.B. No. 15, SARIGAM P.O., VALSAD – 396 155, GUJARAT, INDIA.

CERTIFICATE
This is to certify that the PROJECT FILE work done by Shria Shettigar
Seat No :________

IN PARTIAL FULFILMENT OF THE REQUIREMENT FOR THE PRACTICAL IN


COMPUTER SCIENCE (083) OF

CLASS XII SCIENCE

The project file work was carried out under our supervision and is certified further
that to the best of our knowledge, the work reported here does not form part of any
other thesis or dissertation of any other candidate.

INTERNAL EXAMINER PRINCIPAL

_________________ ______________

Laxmi International School


Sarigam
________________
EXTERNAL EXAMINER

2|Page
ACKNOWLEDGEMENT
I undertook this Project work, as the part of my XII-Computer Science course. I had tried to
apply my best of knowledge and experience, gained during the study and class work
experience. However, developing software system is generally a quite complex and time-
consuming process. It requires a systematic study, insight vision and professional approach
during the design and development. Moreover, the developer always feels the need, the help
and good wishes of the people near you, who have considerable experience and idea.

I would like to extend my sincere thanks and gratitude to my teacher Mrs. Krunali Prajapati
for her valuable guidance in our practical work.
I am very much thankful to our Vice Principal Sir Mr. Javed Shaikh for his immense help in
carrying out this project work.

I whole heartily wish to thank our Principal Sir Mr. Pravin Pawar for providing us the
wonderful platform, valuable time and moral support to develop this software.

I would like to take the opportunity to extend my sincere thanks and gratitude to my father
Mr. Manoj Shettigar and my mother Mrs. Shubhangini Shettigar for being a source of
inspiration and providing time and freedom to develop this software project.

Shria Shettigar

3|Page
INDEX:
R.NO TITLE PAGE NO SIGN

1. Introduction of Python & MySQL 5

2. Introduction to project 6

3. Import Statements 7

4. Source codes 8

5. Output Windows 12

6. Bibliography 15

INTRODUCTION TO PYTHON

Python is an easy-to-learn yet powerful object oriented programming language. It is a very


high level programming language yet as powerful as many other middle-level not so high-
level languages like C, C++, Java, etc.
Python programming language was developed by Guido VanRossum in February 1991.
Python is an interpreted high level language. It is a platform independence language.

4|Page
Python is a general-purpose coding language—which means that, unlike HTML, CSS, and
JavaScript, it can be used for other types of programming and software development besides
web development. That includes back end development, software development, data science
and writing system scripts among other things.

INTRODUCTION TO MYSQL

MY SQL is an RDBMS and ships with no GUI tools to administer MYSQL databases or
manage data contained within the databases. Users may use the included command linetools,
or use MYSQL “front-ends”, desktop software and web applications that create and manage
MYSQL databases, build database structures, back up data, inspect status, and work with data
records. The official set of MYSQL front-end tools, MYSQL_Workbench is actively
developed by Oracle, and is freely available for use.
Many of the world’s largest and fastest-growing organizations use MYSQL, to save time and
money powering.
MYSQL was originally founded and developed by Sweden by two Swedes and a Finn:
David Axmark, Allan Larsson and Michael “Monty” Widenius, who had worked together
since the 1980’s.

Introduction to Project
My Project – “Expense Tracker” is a tool that helps you monitor and manage the
costs associated with your project. It can help you plan your budget, track your
spending, and identify any cost overruns or savings. A project expense tracker can
also help you communicate your project status and financial performance to your
stakeholders. There are different types of project expense trackers, depending on
your project size, scope, and complexity.

5|Page
Import Statements

• import mysql.connector

MySQL Connectors provide connectivity to the MySQL server for client programs. APIs
provide low-level access to MySQL resources using either the classic MySQL protocol or X
Protocol

6|Page
• import datetime

This statement in Python allows you to access the datetime module, which provides
classes and functions for working with dates and times. The datetime module can help you
create, manipulate, and format date and time objects in Python.

Source Codes
# Importing the necessary modules
import mysql.connector
import datetime

# Connecting to the MySQL database


db =
mysql.connector.connect(host="localhost",user="root",passwd="ti
ger",database="expense_tracker")

# Creating a cursor object to execute SQL queries


cursor = db.cursor()

# Creating a table to store the expense records

7|Page
cursor.execute("CREATE TABLE IF NOT EXISTS expenses (id INT
AUTO_INCREMENT PRIMARY KEY, date DATE, category VARCHAR(255),
description VARCHAR(255), amount DECIMAL(10,2))")

# A function to insert a new expense record into the table


def add_expense(date, category, description, amount):
sql = "INSERT INTO expenses (date, category, description,
amount) VALUES (%s, %s, %s, %s)"
val = (date, category, description, amount)
cursor.execute(sql, val)
db.commit()
print(cursor.rowcount, "record inserted.")

# A function to display all the expense records from the table


def show_expenses():
sql = "SELECT * FROM expenses"
cursor.execute(sql)
result = cursor.fetchall()
print("ID\tDate\t\tCategory\tDescription\tAmount")
for row in result:
print(row[0], "\t", row[1], "\t", row[2], "\t\t",
row[3], "\t\t", row[4])

# A function to display the total expenses by category


def show_total_by_category():
sql = "SELECT category, SUM(amount) FROM expenses GROUP BY
category"
cursor.execute(sql)
result = cursor.fetchall()
print("Category\tTotal")
for row in result:
print(row[0], "\t\t", row[1])

# A function to display the total expenses by month


def show_total_by_month():
sql = "SELECT MONTH(date), SUM(amount) FROM expenses GROUP
BY MONTH(date)"
cursor.execute(sql)
result = cursor.fetchall()
print("Month\tTotal")

8|Page
for row in result:
print(row[0], "\t", row[1])

# A function to delete an expense record by id


def delete_expense(id):
sql = "DELETE FROM expenses WHERE id = %s"
val = (id,)
cursor.execute(sql, val)
db.commit()
print(cursor.rowcount, "record deleted.")

# A function to update an expense record by id


def update_expense(id, date, category, description, amount):
sql = "UPDATE expenses SET date = %s, category = %s,
description = %s, amount = %s WHERE id = %s"
val = (date, category, description, amount, id)
cursor.execute(sql, val)
db.commit()
print(cursor.rowcount, "record updated.")

# A function to display the menu options


def show_menu():
print("Welcome to the Expense Tracker!")
print("Please choose an option:")
print("1. Add a new expense")
print("2. Show all expenses")
print("3. Show total expenses by category")
print("4. Show total expenses by month")
print("5. Delete an expense")
print("6. Update an expense")
print("7. Exit")

# A loop to run the program until the user chooses to exit


while True:
show_menu()
choice = input("Enter your choice: ")
if choice == "1":
date = input("Enter the date (YYYY-MM-DD): ")

9|Page
category = input("Enter the category [Assign a label to
your expense based on the type or purpose of the spending. Eg:
food, rent, utilities, entertainment, etc.]: ")
description = input("Enter the description [Add a brief
note of the expense.Eg:“groceries for the week” or “electricity
bill for June” etc.]: ")
amount = input("Enter the amount: ")
add_expense(date, category, description, amount)
elif choice == "2":
show_expenses()
elif choice == "3":
show_total_by_category()
elif choice == "4":
show_total_by_month()
elif choice == "5":
id = input("Enter the id of the expense to delete: ")
delete_expense(id)
elif choice == "6":
id = input("Enter the id of the expense to update: ")
date = input("Enter the new date (YYYY-MM-DD): ")
category = input("Enter the new category: ")
description = input("Enter the new description: ")
amount = input("Enter the new amount: ")
update_expense(id, date, category, description, amount)
elif choice == "7":
print("Thank you for using the Expense Tracker!")
break
else:
print("Invalid choice. Please try again.")

10 | P a g e
Output Windows

Python window

Opening window

11 | P a g e
Window to add a new expense

Window to show all expenses

Window to show total expenses by category

Window to show total expenses by month

Window to delete an expense

12 | P a g e
Window to update an expense

Window to exit

13 | P a g e
Sql window

Bibliography

14 | P a g e
15 | P a g e

You might also like