CS Project

Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

INDEX

SL.NO. TOPIC PAGE NUMBER


1 PYTHON 2
2 SQL 3
3 INTEGRATING PYTHON WITH MY 5
SQL
4 STEPS FOR INTEGRATING 6
PYTHON WITH MY SQL
5 SOFTWARE AND HARDWARE 7
USED
6 SOURCE CODE 8
7 OUTPUTS 11
8 RELEVANCE 14
9 CONCLUSION 15
PYTHON

Python is a high-level, versatile, and interpreted programming language known for its
simplicity and readability. Created by Guido van Rossum and first released in 1991,
Python has gained widespread popularity due to its ease of use, extensive standard
library, and vibrant community support. Its syntax emphasizes code readability and
clarity, making it an excellent choice for both beginners and experienced developers.

Python's popularity is attributed to its extensive standard library, which provides


pre-built modules and functions for various tasks, such as handling files, working
with data structures, networking, and more. Additionally, Python has a vibrant and
active community that contributes to a rich ecosystem of third-party libraries and
frameworks, catering to diverse domains such as web development, data science,
machine learning, scientific computing, and automation.

Python's indentation-based block structure enforces clean and consistent code


formatting, reducing syntactic clutter and encouraging good coding practices. Its
dynamic typing system allows variables to change types on the fly, enhancing
flexibility but also requiring careful attention to type-related issues.

Python's popularity is largely in part due to its active community of developers who
contribute to the language's growth by creating packages and libraries that extend its
capabilities. The language’s ease of learning makes it an ideal choice for beginners
while its versatility makes it a favorite among seasoned programmers as well

Python's versatility enables it to be used in a wide range of applications, from web


development and scientific research to automation, data analysis, artificial
intelligence, and more. Its cross-platform compatibility allows developers to write
code once and run it on different operating systems. Python's popularity and active
community ensure a steady stream of learning resources, tutorials, and
community-driven support.
SQL

SQL, or Structured Query Language, is a domain-specific programming language


designed for managing, querying, and manipulating relational databases. It serves as
the standard interface for interacting with relational database management systems
(RDBMS), facilitating the creation, modification, retrieval, and deletion of data, as well
as the definition and maintenance of database schemas and structures. SQL
operates through a set of declarative statements that specify desired operations on
data and metadata stored in a relational database.

SQL offers several advantages that make it a powerful and widely-used language for
managing and interacting with relational database:
1) Data Integrity and Consistency:
SQL enforces data integrity by allowing you to define rules and relationships between
data elements. For instance, you can set up primary keys to ensure each record in a
table has a unique identifier. This prevents duplicate entries and maintains data
accuracy. Foreign keys establish relationships between tables, ensuring that data in
one table references valid data in another. Additionally, SQL supports constraints
that prevent inappropriate or inconsistent data from being entered. For example, you
can set a constraint to ensure that a birth date is always before the current date.
These features collectively maintain the consistency and reliability of your data.
2) Efficient Data Retrieval:
SQL databases use indexing mechanisms to speed up data retrieval. An index is like
a roadmap that helps the database quickly locate relevant rows. By creating indexes
on frequently queried columns, you significantly reduce the time it takes to find
specific data. This efficiency is especially crucial when dealing with large datasets.
Without indexing, queries would require scanning the entire dataset, resulting in
slower performance. SQL's indexing capabilities enhance data retrieval speed,
making applications more responsive and scalable.
3) Flexible Data Manipulation:
SQL provides a versatile set of commands for querying and manipulating data. The
SELECT statement is particularly powerful, allowing you to retrieve data based on
complex conditions, join tables, aggregate values, and sort results. This flexibility
enables you to tailor queries to your specific needs, extracting valuable insights from
your data. SQL's ability to perform calculations, summarizations, and transformations
directly within the database reduces the need for complex data manipulation in
external code. This not only streamlines your code but also improves performance
by leveraging the database engine's optimizations.

SQL has limitations, including challenges with handling extremely large datasets
efficiently, complexity in managing hierarchical data structures, rigidity in schema
changes, performance bottlenecks in complex joins, a learning curve for effective
usage, and potential vendor lock-in due to different RDBMS variations. Additionally,
for small projects, SQL's overhead might outweigh benefits. These disadvantages
can impact scalability, agility, and overall performance, urging consideration of
alternative database solutions for specific use cases.

SQL is utilized across a broad spectrum of applications, ranging from business and
finance to scientific research and web development, due to its ability to manage
structured data effectively and efficiently. Different relational database management
systems may implement SQL with variations in syntax, features, and optimizations.
INTEGRATING PYTHON WITH MYSQL

Linking Python with MySQL offers several advantages such as

1) Data Manipulation: Python's flexibility and extensive libraries enable


complex data manipulation and analysis, enhancing the power of MySQL
databases for data-driven applications.
2) Rich Ecosystem: Python has a vast ecosystem of libraries for various
tasks, such as data visualization (Matplotlib, Seaborn), machine learning
(Scikit-learn, TensorFlow), and web development (Django, Flask).
3) Automation and Integration: Python scripts can automate data insertion,
retrieval, and updates in MySQL databases, streamlining data workflows
and enhancing integration between different systems.
4) Rapid Development: Python's concise syntax and dynamic typing speed
up development, allowing you to quickly prototype and iterate
applications that interact with MySQL databases.
5) Data Analysis: Python's data analysis libraries can process MySQL data,
enabling in-depth analysis, reporting, and business intelligence.
6) Web Development: Python's frameworks like Django and Flask can
seamlessly integrate with MySQL, facilitating web application
development and database interaction.

However, there are also certain disadvantages which need to be considered


1) Security Concerns: Improper handling of queries may lead to SQL
injection vulnerabilities. Proper sanitization and parameterized queries
are essential to prevent this risk.
2) Performance Issues: Python's execution can be slower than compiled
languages, potentially impacting real-time applications heavily reliant on
frequent database interactions.
3) Complexity: Integrating Python with MySQL requires learning both
languages and managing additional libraries, increasing the complexity of
your project.
4) Compatibility: As both Python and MySQL have frequent updates,
ensuring compatibility between different versions can be challenging.
STEPS FOR INTEGRATING PYTHON WITH MYSQL

Integrating Python with MySQL involves utilizing libraries that facilitate communication
between Python programs and MySQL databases. One popular library for this purpose is
mysql-connector-python. Here's a concise guide to get you started:

Install the MySQL Connector:


Begin by installing the mysql-connector-python library using the pip package manager:

pip install mysql-connector-python


Import the Library:
In your Python script, import the MySQL Connector library:
**import mysql.connector

Establish a Connection:
To connect to your MySQL database, provide the necessary connection details such as
hostname, username, password, and database name:
**mydb=mysql.connector.connect(host="localhost", user="username password="password",
database="databasename")

Create a Cursor:
Create a cursor object to interact with the database:
**mycursor = mydb.cursor()

Execute Queries:
You can execute SQL queries using the cursor's execute() method:
**mycursor.execute("SELECT * FROM tablename")

Fetch Results:
Retrieve the query results using methods like fetchone() or fetchall():
**result = mycursor.fetchall()
for row in result:
print(row)

Commit Changes:
If you modify the database, don't forget to commit the changes:
**mydb.commit()

Close Connection:
Finally, close the connection when you're done:
**mydb.close()
SOFTWARE USED

● Windows 10
● Python
● MYSQL

HARDWARE USED

● AMD - RYZEN 5 (2600x)


● NVIDIA 1660ti
● 16 gb ram
● Monitor
● Keyboard
● Mouse
SOURCE CODE

import mysql.connector

def view_items(cursor):
cursor.execute('SELECT * FROM items')
all_items = cursor.fetchall()
for item in all_items:
print("ID:", item[0])
print("Name:", item[1])
print("Quantity:", item[2])
print("Price:", item[3])
print("--------------------------")

def add_item(cursor, conn):


item = {}
item['id']=input("enter id here:")
item['name'] = input('Item name: ')
item['quantity'] = int(input('Item quantity: '))
item['price'] = int(input('Price $: '))

cursor.execute('INSERT INTO items (id,name, quantity, price)


VALUES (%s,%s, %s, %s)', (item['id'],item['name'], item['quantity'],
item['price']))
conn.commit()
print('Item has been successfully added.')

def purchase_item(cursor, conn):


purchase_item = input('Which item do you want to purchase? Enter
name: ')
cursor.execute('UPDATE items SET quantity = quantity - 1 WHERE
name = %s', (purchase_item,))
conn.commit()
print('Pay for', purchase_item, 'at checkout counter.')

def search_item(cursor):
find_item = input("Enter the item's name to search in inventory: ")
cursor.execute('SELECT * FROM items WHERE name = %s',
(find_item,))
found_item = cursor.fetchone()
if found_item:
print('The item named', find_item, 'is displayed below with its
details:')
print("ID:", found_item[0])
print("Name:", found_item[1])
print("Quantity:", found_item[2])
print("Price:", found_item[3])
else:
print('Item not found.')

def edit_item(cursor, conn):


item_name = input('Enter the name of the item that you want to edit: ')
cursor.execute('SELECT * FROM items WHERE name = %s',
(item_name,))
found_item = cursor.fetchone()

if found_item:
print('Here are the current details of', item_name)
print("ID:", found_item[0])
print("Name:", found_item[1])
print("Quantity:", found_item[2])
print("Price:", found_item[3])

new_name = input('New item name: ')


new_quantity = int(input('New item quantity: '))
new_prifookce = int(input('New Price $: '))

cursor.execute('UPDATE items SET name = %s, quantity = %s,


price = %s WHERE id = %s',
(new_name, new_quantity, new_price, found_item[0]))
conn.commit()
print('Item has been successfully updated.')
else:
print('Item not found.')

# Connect to the MySQL database


conn = mysql.connector.connect(
host="localhost",
user="root",
password="123456",
database="groceries"
)
cursor = conn.cursor()

while True:
print('------------------Welcome to the supermarket------------------')
print('1. View items\n2. Add items for sale\n3. Purchase items\n4. Search
items\n5. Edit items\n6. Exit')
choice = input('Enter the number of your choice: ')

if choice == '1':
view_items(cursor)

elif choice == '2':


add_item(cursor, conn)

elif choice == '3':


purchase_item(cursor, conn)

elif choice == '4':


search_item(cursor)

elif choice == '5':


edit_item(cursor, conn)

elif choice == '6':


print('------------------exited------------------')
break

# Close the database connection when done


conn.close()
OUTPUTS
RELEVANCE

The Supermarket Management System project presents a basic yet functional


solution for addressing the inventory management needs of supermarkets. By
allowing users to add, view, purchase, search for, and edit items in the
inventory, the code provides a foundation for organizing supermarket
operations. However, its significance goes beyond its immediate functionality.
At its core, the project serves as a foundational solution for managing inventory.
It establishes the fundamental processes required for maintaining accurate
records of products and their attributes. While the current implementation is
relatively simple, it lays the groundwork for more advanced inventory
management systems that can incorporate real-time updates, analytics, and
predictive modeling.
Inventory management is a critical aspect of any retail operation, including
supermarkets. Efficient inventory management ensures that products are readily
available, reduces waste due to overstocking or spoilage, and provides insights
into consumer preferences. The code's ability to manage items, update
quantities, and simulate purchases demonstrates its relevance in streamlining
these essential processes.
In the rapidly evolving landscape of retail and technology, supermarket
management systems must adapt to changing needs. The project's modularity
allows for easy integration of new features and functionalities as requirements
evolve. This adaptability ensures that the project can remain relevant and
effective in addressing the dynamic challenges faced by supermarkets.
CONCLUSION

The Supermarket Management System code provides a foundational solution


for managing a supermarket's inventory and operations. Its relevance in
inventory management, educational purposes, and potential for expansion make
it a valuable starting point for building more comprehensive supermarket
management applications. By considering future applications and
enhancements, this code can evolve to meet the changing needs of supermarkets
and retailers.
BIBLIOGRAPHY

● Class 11 NCERT
● Class 12 NCERT
● Computer Science with python for grade XII - Sumita Arora
● Wikipedia

You might also like