0% found this document useful (0 votes)
20 views17 pages

Python Varshini

Uploaded by

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

Python Varshini

Uploaded by

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

INDEX

 Synopsis

 About Python:

 Python is an interpreted, high-level language, popular for its readability, versatility,


and wide range of applications (web development, data science, AI, etc.).

 About MySQL:

 MySQL is a widely used open-source relational database management system known


for performance, scalability, and ease of use.

 Python-MySQL Integration (Source Code):

 A Python script that connects to a MySQL database, allowing users to:

o Add new contacts (with mobile number, name, address, and email).
o Search/view contacts based on various criteria.
o Delete contacts by name.
SYNOPSIS

The script establishes a connection to a MySQL database and defines functions to


perform various operations on a "contacts" table. The contact book supports functionalities
such as adding, displaying, searching, updating, and deleting contacts. Additionally, it
includes features to export contacts to a CSV file, import contacts from a CSV file, and
count the total number of contacts.
The script connects to a MySQL database using provided credentials. A "contacts" table
is created (if not exists) in the connected database, with columns for contact information
such as name, phone number, and email. Functions are defined to add, display, search,
update, and delete contacts from the database. The script presents a simple command-line
menu for users to interact with the contact book. Users can choose options to perform
specific operations. Basic input validation is implemented, including checking for valid
phone numbers and non-empty names. The script provides an option to count and display the
total number of contacts in the database.
The script focuses on functionality and basic error handling. There’s room for
improvements in terms of security, user interface, and code organization. Database
credentials are hardcoded, which may pose security risks. Storing them securely is
recommended. Additional input validation and user feedback could enhance the user
experience.
ABOUT PYTHON

Python is a high-level, interpreted programming language known for its readability,


simplicity, and versatility. It was created by Guido van Rossum and first released in 1991.
Python has gained widespread popularity in various domains, including web development,
data science, artificial intelligence, automation, and more. Here are some key aspects of
Python:

1. Readability:

Python emphasizes code readability and a clean syntax. The language is designed to be
easily readable and requires fewer lines of code compared to languages like C++ or Java.

2. Interpreted Language:

Python is an interpreted language, meaning that the Python code is executed line by line,
and it does not need to be compiled into machine code before running. This makes
development and debugging faster.

3. Versatility:

Python is a versatile language with a large standard library and a vast ecosystem of third-
party libraries and frameworks. This makes it suitable for a wide range of applications,
from web development (Django, Flask) to scientific computing (NumPy, SciPy) and
machine learning (TensorFlow, PyTorch).

4. Object-Oriented:

Python supports object-oriented, imperative, and functional programming paradigms. It


allows developers to write code using classes and objects, facilitating code organization
and reusability.

5. Dynamic Typing:

Python is dynamically typed, meaning that you don't need to specify the data type of a
variable explicitly. This allows for more flexibility but requires careful attention to
variable types during runtime.
6. Large Community and Support:

Python has a large and active community of developers. This community contributes to
the language's growth, provides support through forums and documentation, and creates a
wealth of open-source libraries and tools.

7. Cross-Platform:

Python is a cross-platform language, meaning that Python code can run on various
operating systems without modification. This cross-platform compatibility contributes to
its widespread adoption.

8. Popular Use Cases:


Python is used in various domains, including:

 Web Development: Django, Flask, Pyramid.


 Data Science and Machine Learning: NumPy, Pandas, SciPy, Scikit-Learn.
 Artificial Intelligence: TensorFlow, PyTorch.
 Automation and Scripting: Python is often used for writing scripts and automating
repetitive tasks.

9. Community-driven Development:

Python's development and enhancement are community-driven, with a transparent and


open development process. The Python Enhancement Proposals (PEP) system guides the
evolution of the language.
ABOUT MYSQL

MySQL is an open-source relational database management system (RDBMS) that


has gained widespread popularity for its reliability, performance, and ease of use. Here are
some key aspects of MySQL:

1. Relational Database Management System (RDBMS):

MySQL is a relational database, which means it organizes data into tables with rows and
columns. It follows the principles of the relational model, facilitating the management
and retrieval of structured data.

2. Open Source:

MySQL is an open-source software, which means that its source code is freely available
to the public. This encourages collaboration and allows developers to modify the code to
suit their specific needs.

3. Ease of Use:

MySQL is known for its ease of use and straightforward setup process. It provides a
command-line interface (CLI) as well as graphical user interfaces (GUIs) like MySQL
Workbench for easier management of databases.

4. Cross-Platform Compatibility:

MySQL is designed to run on various operating systems, including Windows, macOS,


Linux, and more. This cross-platform compatibility makes it a versatile choice for
different environments.

5. Scalability:

MySQL is scalable and can handle both small-scale and large-scale database applications.
It supports various storage engines, allowing developers to choose the one that best fits
their specific requirements.
6. ACID Compliance:

MySQL adheres to the principles of ACID (Atomicity, Consistency, Isolation, Durability),


ensuring that database transactions are reliable and maintain data integrity.

7. High Performance:

MySQL is known for its high performance, making it suitable for applications with
demanding data processing needs. It includes features such as caching, indexing, and
optimized algorithms to enhance performance.

8. Community and Support:

MySQL has a large and active community of developers, users, and contributors. This
community provides support through forums, documentation, and contributions to the
improvement of the MySQL ecosystem.

9. Security:

MySQL incorporates security features such as access controls, encryption, and


authentication mechanisms to ensure the protection of sensitive data.

10. Integration with Programming Languages: -

MySQL is commonly used in conjunction with various programming languages, including


Python, PHP, Java, and more.This integration allows developers to build dynamic and data-
driven applications.

11. Replication and High Availability:

MySQL supports replication, allowing data to be copied to multiple servers for backup or
load balancing. This enhances data availability and provides a level of fault tolerance.

12. Regular Updates: -

MySQL is actively developed and receives regular updates to introduce new features,
improve performance, and address security concerns.
SYSTEM REQUIREMENTS

Minimum system requirements

 Modern Operating System: WINDOWS MAC OR LINUX


 x86-bit CPU (Intel / AMD architecture).
 2GBRAM.

Recommended system requirements

 Modern Operating System: WIN 10 or 11


MAC OS X 10.11 or higher, 64 bit
LINUX : RHEL 6/7, 64-bit (almost all libraries also work in Ubuntu)
 INTEL ® CORE™ i5 or higher
AMD Athlon™ 3000 or higher
 4GB RAM

Recommended software’s:

 MySQL
 python
SOURCE
CODE
import mysql.connector as cd

# Connecting to the database


mydb = cd.connect(host="localhost", user="root", passwd="tiger",
database="contact_book")
mycursor = mydb.cursor()

# Function to add a new contact


def add_contact():
L = []
mobile_no = input("Enter Mobile number (10 Digits): ")
L.append(mobile_no)

name = input("Enter the Name: ")


L.append(name)

address = input("Enter address: ")


L.append(address)

email = input("Enter the email: ")


L.append(email)

cont = tuple(L)
sql = "INSERT INTO contact_book (mobile_no, name, address, email) VALUES (%s,
%s, %s, %s)"
mycursor.execute(sql, cont)
mydb.commit()
print("Contact added successfully!\n")

# Function to view/search contacts based on different criteria


def view_contact():
print("Select the search criteria: ")
print("1. Mobile_no")
print("2. Name")
print("3. Address")
print("4. Email")
print("5. View All contacts")

ch = int(input("Enter your choice: "))

if ch == 1:
s = input("Enter Mobile Number: ")
rl = (s,)
sql = "SELECT * FROM contact_book WHERE mobile_no = %s"
mycursor.execute(sql, rl)

elif ch == 2:
nm = input("Enter Name: ")
sql = "SELECT * FROM contact_book WHERE name = %s"
mycursor.execute(sql, (nm,))

elif ch == 3:
s = input("Enter Address: ")
sql = "SELECT * FROM contact_book WHERE address = %s"
mycursor.execute(sql, (s,))

elif ch == 4:
s = input("Enter Email: ")
sql = "SELECT * FROM contact_book WHERE email = %s"
mycursor.execute(sql, (s,))

elif ch == 5:
sql = "SELECT * FROM contact_book"
mycursor.execute(sql)

res = mycursor.fetchall()
if res:
print("Contact details are as follows: (mobile_no, name, address, email)")
for x in res:
print(x)
else:
print("No contact found.")
# Function to delete a contact
def del_contact():
name = input("Enter the name of the contact to be deleted: ")
sql = "DELETE FROM contact_book WHERE name = %s"
mycursor.execute(sql, (name,))
mydb.commit()
print(f"Contact '{name}' deleted successfully!\n")

# Main menu function


def main_menu():
while True:
print("\nMain Menu")
print("1: Add New Contact")
print("2: View/Search Contact")
print("3: Delete Contact")
print("4: Exit")

try:
userInput = int(input("Please select an option: "))
except ValueError:
print("Invalid input! Please enter a number.")
continue

if userInput == 1:
add_contact()
elif userInput == 2:
view_contact()
elif userInput == 3:
del_contact()
elif userInput == 4:
print("Exiting the application.")
break
else:
print("Invalid option! Please choose a valid option.")

# Calling the main menu function


main_menu()
OUTPUT
SEARCHING:
ADDING A RECORD:
ALL RECORD SEARCH :
DATA BASE VIEW :
BIBILIOGRAPHY

 www.Github.com

 www.w3schools.com

 www.Stackoverflow.com

 www.freeCodeCamp.com

 www.Geeksforgeeks.com

You might also like