0% found this document useful (0 votes)
16 views

Python_ Advantages, Diversification, and Future-Proofing - Google Docs

Uploaded by

brrakhulvarshan
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)
16 views

Python_ Advantages, Diversification, and Future-Proofing - Google Docs

Uploaded by

brrakhulvarshan
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/ 45

‭ ython: Advantages, Diversification, and‬

P
‭Future-Proofing‬
‭ ython is a dynamic and versatile programming language that has become‬
P
‭one of the most widely used languages in the world today. Created by‬
‭Guido van Rossum in 1991, Python has evolved into a powerful tool for‬
‭developers, enabling them to write code quickly and efficiently. Its ease of‬
‭use, readability, and wide range of applications make it an ideal choice for‬
‭beginners and experienced developers alike.‬

‭Advantages of Python‬
‭1.‬ ‭Simple and Readable Syntax‬‭: One of Python's key strengths‬‭is its‬
‭simplicity and readability. The syntax is clean and straightforward,‬
‭making it easier to learn for beginners. Its use of indentation instead‬
‭of braces or semicolons to define code blocks promotes readability,‬
‭which is particularly beneficial for collaboration and maintenance of‬
‭code.‬
‭2.‬ ‭Extensive Standard Library‬‭: Python comes with a rich‬‭standard‬
‭library that provides modules and functions for handling common‬
‭programming tasks. From file I/O and networking to regular‬
‭expressions and working with dates, Python’s standard library‬
‭significantly reduces the need for external packages, speeding up‬
‭development.‬
‭3.‬ ‭Cross-Platform Compatibility‬‭: Python is inherently‬‭cross-platform,‬
‭meaning code written in Python can run on different operating‬
‭systems, such as Windows, macOS, and Linux, with minimal‬
‭adjustments. This makes Python ideal for developing applications‬
‭that need to run across various platforms without additional‬
‭complexity.‬
‭4.‬ ‭Large and Active Community‬‭: Python has a massive,‬‭active‬
‭community of developers and users, making it easier to find‬
‭resources, tutorials, and support. The Python Package Index (PyPI)‬
‭contains thousands of third-party libraries, ensuring that Python‬

‭1‬
‭ evelopers can easily extend their applications without needing to‬
d
‭reinvent the wheel.‬
‭5.‬ ‭Integration and Automation‬‭: Python is well-suited‬‭for integrating‬
‭with other languages and technologies. It can easily be used to‬
‭automate repetitive tasks, such as file management, web scraping,‬
‭and system monitoring. Additionally, Python is commonly employed‬
‭as a scripting language for embedding in applications written in other‬
‭languages.‬
‭6.‬ ‭Wide Range of Applications‬‭: Python can be used for‬‭various types‬
‭of development, including web development, data analysis, machine‬
‭learning, automation, and game development. Its versatility means‬
‭that it can be applied in diverse industries, including finance,‬
‭healthcare, gaming, and scientific research.‬

‭Diversification of Python‬
‭1.‬ ‭Web Development‬‭: Python has seen tremendous growth‬‭in web‬
‭development, especially with frameworks like Django and Flask.‬
‭Django, known for its "batteries-included" philosophy, provides a‬
‭complete toolkit for building web applications, from authentication to‬
‭database handling. Flask, on the other hand, is a lightweight‬
‭framework for developers who prefer more flexibility and‬
‭customization.‬
‭2.‬ ‭Data Science and Machine Learning‬‭: Python’s rise in‬‭data science‬
‭and machine learning is attributed to libraries such as NumPy,‬
‭Pandas, Matplotlib, and Seaborn, which make it easier to analyze‬
‭and visualize data. More advanced frameworks like TensorFlow and‬
‭PyTorch have become the go-to tools for deep learning, allowing‬
‭developers to build and train sophisticated machine learning models.‬
‭3.‬ ‭Automation and Scripting‬‭: Python excels at automating‬‭repetitive‬
‭tasks. Scripts written in Python are widely used to automate system‬
‭administration, process data, scrape websites, and manage cloud‬
‭services. Python’s simplicity and ease of use make it a popular‬
‭choice for anyone looking to automate manual work, saving time and‬
‭reducing human error.‬

‭2‬
‭4.‬ ‭Artificial Intelligence and Robotics‬‭: Python's application extends‬
‭into cutting-edge technologies like AI and robotics. Libraries such as‬
‭OpenCV for computer vision, TensorFlow and Keras for machine‬
‭learning, and ROS (Robot Operating System) for robotics, all provide‬
‭powerful tools for creating intelligent systems. Python is often the‬
‭language of choice for prototyping and building intelligent‬
‭applications.‬
‭5.‬ ‭Game Development‬‭: While Python is not traditionally‬‭used for AAA‬
‭games, it is still widely used in game development for scripting,‬
‭prototyping, and creating smaller indie games. The popular Pygame‬
‭library provides tools for game creation and is used by developers to‬
‭build games and simulations.‬

‭Future-Proofing with Python‬


‭ ython’s future is promising, largely due to its continued evolution and the‬
P
‭increasing demand for skills in emerging fields such as AI, machine‬
‭learning, data science, and automation. Several factors contribute to‬
‭Python's future-proof status:‬

‭1.‬ ‭Rising Demand in Key Industries‬‭: As industries like‬‭healthcare,‬


‭finance, and education adopt AI and machine learning, Python’s role‬
‭in these sectors will continue to grow. Its dominance in data analysis‬
‭and machine learning, powered by frameworks like TensorFlow and‬
‭PyTorch, makes it a cornerstone of modern technological‬
‭development.‬
‭2.‬ ‭Continual Language Improvement‬‭: Python is consistently‬‭updated,‬
‭with new features and improvements added regularly. The Python‬
‭Software Foundation (PSF) oversees Python’s development,‬
‭ensuring that it remains relevant by integrating modern features while‬
‭maintaining backward compatibility. This approach ensures that‬
‭Python will continue to meet the needs of developers for years to‬
‭come.‬
‭3.‬ ‭Extensive Ecosystem‬‭: The large ecosystem of libraries‬‭and‬
‭frameworks will keep Python competitive in the future. As the Python‬

‭3‬
c‭ ommunity grows, the number of open-source libraries available for‬
‭various tasks will continue to expand, keeping Python developers at‬
‭the forefront of innovation.‬
‭4.‬ ‭Python in Education‬‭: Python is widely used in academic‬‭settings,‬
‭especially in computer science courses. Its simplicity and ease of‬
‭learning make it an excellent first language for students, ensuring that‬
‭the next generation of developers will be well-versed in Python,‬
‭fostering continued growth.‬
‭5.‬ ‭Support for Emerging Technologies‬‭: Python has shown‬‭its‬
‭adaptability in fields such as blockchain, quantum computing, and‬
‭cybersecurity. As new technologies continue to emerge, Python’s‬
‭flexible design and vast library support will allow it to remain an‬
‭essential tool for developers exploring cutting-edge fields.‬

‭Conclusion‬
‭ ython’s advantages, including its simplicity, readability, and versatility,‬
P
‭have made it a dominant force in the programming world. Its applications‬
‭span a wide range of industries, from web development and data science‬
‭to artificial intelligence and automation. Python’s future looks bright, with its‬
‭continuous growth in emerging fields and ongoing community support.‬
‭Whether you're a beginner or an experienced developer, learning Python is‬
‭a valuable investment that will pay off for years to come.‬

‭4‬
‭ QL: Advantages, Diversification, and‬
S
‭Future-Proofing‬
‭ tructured Query Language (SQL) is the standard language used to‬
S
‭manage and manipulate relational databases. Since its inception in the‬
‭1970s by IBM, SQL has remained one of the most important tools for‬
‭developers, data analysts, and database administrators. SQL is essential‬
‭for managing large amounts of data and is a core skill for anyone working‬
‭with databases or data-driven applications.‬

‭Advantages of SQL‬
‭1.‬ ‭Standardized Language‬‭: SQL is a standardized language‬‭used by‬
‭nearly all relational database management systems (RDBMS), such‬
‭as MySQL, PostgreSQL, Microsoft SQL Server, and Oracle. This‬
‭universality means that once you learn SQL, you can work with‬
‭different database systems, which adds significant flexibility to your‬
‭skillset.‬
‭2.‬ ‭Simplicity and Ease of Use‬‭: SQL is designed to be‬‭easy to learn‬
‭and use, with a syntax that is both intuitive and readable. Its‬
‭declarative nature means that users focus on specifying‬‭what‬‭data‬
‭they want, rather than‬‭how‬‭to retrieve it, making‬‭SQL accessible to‬
‭non-programmers and business analysts as well.‬
‭3.‬ ‭Powerful Data Manipulation‬‭: SQL provides powerful‬‭capabilities for‬
‭querying, updating, and managing data in a relational database. It‬
‭allows for complex filtering, sorting, and aggregation of data. SQL‬
‭queries can join multiple tables, group data, and apply complex‬
‭mathematical operations to derive valuable insights.‬
‭4.‬ ‭Data Integrity and Security‬‭: SQL databases are designed‬‭to‬
‭enforce data integrity through constraints such as primary keys,‬
‭foreign keys, and unique constraints. These ensure that the data is‬
‭accurate, consistent, and reliable. SQL also allows for sophisticated‬
‭access control mechanisms, ensuring that only authorized users can‬
‭access or modify certain data.‬

‭5‬
‭5.‬ ‭Support for Transactions‬‭: SQL supports transactional operations,‬
‭which ensures that a series of database operations are executed as a‬
‭single unit. If any part of the transaction fails, the entire operation can‬
‭be rolled back to maintain data consistency and integrity. This is‬
‭crucial for systems where reliability and consistency are paramount,‬
‭such as financial applications.‬
‭6.‬ ‭Scalability and Flexibility‬‭: SQL databases can handle‬‭vast amounts‬
‭of data, with the ability to scale vertically by increasing server‬
‭resources or horizontally through techniques like sharding.‬
‭Additionally, SQL supports both structured and semi-structured data,‬
‭allowing businesses to adapt their database systems as their needs‬
‭evolve.‬

‭Diversification of SQL‬
‭1.‬ ‭Business Intelligence and Reporting‬‭: SQL plays a crucial‬‭role in‬
‭the field of business intelligence (BI). It is widely used in reporting‬
‭tools and data analysis applications to pull data from databases,‬
‭allowing businesses to generate real-time reports, dashboards, and‬
‭visualizations. BI platforms like Tableau, Power BI, and Google Data‬
‭Studio integrate SQL queries to extract and analyze data for‬
‭decision-making.‬
‭2.‬ ‭Data Warehousing‬‭: SQL is extensively used in data‬‭warehousing,‬
‭where data from multiple sources is aggregated and stored for‬
‭analysis. Data warehouses rely on SQL-based systems to run‬
‭complex queries that aggregate and summarize large datasets,‬
‭providing valuable insights to organizations. Technologies such as‬
‭Apache Hive and Google BigQuery use SQL-like syntax to interact‬
‭with large-scale distributed data systems.‬
‭3.‬ ‭Web Development and Applications‬‭: In web development,‬‭SQL is‬
‭often used to manage the back-end database of websites and‬
‭applications. SQL databases power the storage of user data,‬
‭transaction records, product catalogs, and more. Frameworks such‬
‭as Django and Ruby on Rails integrate SQL seamlessly to interact‬

‭6‬
‭ ith relational databases, ensuring that dynamic web applications‬
w
‭can handle large amounts of structured data.‬
‭4.‬ ‭Cloud Databases and NoSQL Integration‬‭: SQL has adapted‬‭to the‬
‭cloud era, with cloud platforms like Amazon RDS, Google Cloud SQL,‬
‭and Microsoft Azure offering managed relational database services.‬
‭These platforms provide scalability, backup, and security features,‬
‭allowing businesses to store and access data remotely. Additionally,‬
‭SQL can integrate with NoSQL databases like MongoDB and‬
‭Cassandra for applications requiring both structured and unstructured‬
‭data storage.‬
‭5.‬ ‭Machine Learning and Data Science‬‭: While SQL is traditionally‬‭not‬
‭associated with machine learning, it plays a significant role in data‬
‭preprocessing. Data scientists use SQL to extract, clean, and prepare‬
‭datasets for analysis. Many machine learning models rely on SQL‬
‭databases to store and manage large volumes of training data, and‬
‭tools like TensorFlow, Keras, and Scikit-learn often retrieve data using‬
‭SQL queries.‬
‭6.‬ ‭Mobile and IoT Applications‬‭: SQL is also widely used‬‭in mobile app‬
‭development, especially for managing data on local devices. SQLite,‬
‭a lightweight SQL database engine, is commonly embedded in‬
‭mobile apps for managing offline data. With the rise of the Internet of‬
‭Things (IoT), SQL databases are used to store data from a growing‬
‭number of connected devices, making SQL essential in the‬
‭development of smart devices and applications.‬

‭Future-Proofing with SQL‬


‭1.‬ ‭Ongoing Standardization and Compatibility‬‭: SQL has‬‭been an‬
‭industry standard for decades, and its specifications continue to‬
‭evolve with input from major RDBMS vendors. The language’s‬
‭continued evolution ensures that SQL remains relevant as database‬
‭technology advances. Modern RDBMS platforms also continue to‬
‭improve performance and scalability, making SQL even more‬
‭powerful for enterprise applications.‬

‭7‬
‭2.‬ ‭Cloud Computing and Big Data‬‭: As cloud computing and big data‬
‭technologies become more prevalent, SQL remains at the forefront of‬
‭data management. Major cloud platforms, including AWS, Google‬
‭Cloud, and Microsoft Azure, offer relational database services with‬
‭full support for SQL. Additionally, SQL can be used in conjunction‬
‭with distributed data systems like Apache Hadoop and Apache Spark,‬
‭making it ideal for large-scale data analysis.‬
‭3.‬ ‭Integration with NoSQL and New Technologies‬‭: While‬‭NoSQL‬
‭databases like MongoDB and Cassandra have gained popularity for‬
‭their flexibility with unstructured data, SQL remains relevant due to its‬
‭ability to integrate with these systems. SQL-on-Hadoop technologies,‬
‭such as Apache Hive and Presto, allow organizations to run SQL‬
‭queries on unstructured data stored in Hadoop clusters, bridging the‬
‭gap between traditional relational databases and newer big data‬
‭technologies.‬
‭4.‬ ‭Increased Focus on Data Security‬‭: As data privacy‬‭and security‬
‭concerns grow, SQL databases are increasingly being enhanced with‬
‭features that ensure compliance with data protection regulations,‬
‭such as GDPR and CCPA. SQL allows fine-grained access control,‬
‭auditing, and encryption, ensuring that sensitive data is protected.‬
‭The continued development of these security features will ensure‬
‭SQL's relevance in future applications.‬
‭5.‬ ‭Continued Demand for Data Professionals‬‭: As data-driven‬
‭decision-making becomes more important across industries, the‬
‭demand for professionals skilled in SQL continues to rise. Data‬
‭analysts, data engineers, and database administrators rely on SQL to‬
‭manage, analyze, and manipulate data, and SQL remains a critical‬
‭skill for anyone entering the field of data science.‬
‭6.‬ ‭SQL in the Age of Artificial Intelligence‬‭: As artificial‬‭intelligence‬
‭and machine learning continue to grow in importance, SQL will‬
‭remain integral in managing the vast amounts of structured data‬
‭required to train AI models. Many AI systems rely on SQL databases‬
‭to store training data, and the integration of AI and SQL tools will‬
‭continue to evolve, enabling smarter data management systems.‬

‭8‬
‭Conclusion‬
‭ QL is a powerful and indispensable tool in the world of data management‬
S
‭and manipulation. Its simplicity, versatility, and broad application in various‬
‭industries make it a foundational skill for anyone working with databases.‬
‭Whether you're building web applications, managing data warehouses, or‬
‭analyzing large datasets, SQL provides the tools necessary to work with‬
‭structured data effectively. As cloud computing, big data, and AI‬
‭technologies continue to grow, SQL’s role in the modern technological‬
‭landscape will remain vital, ensuring its future-proof status for years to‬
‭come.‬

‭Introduction to Python MySQL Connectivity‬


‭ ython MySQL connectivity refers to the ability of Python programs to‬
P
‭interact with MySQL databases, enabling them to perform operations such‬
‭as storing, retrieving, updating, and deleting data. This integration is critical‬
‭for creating dynamic, data-driven applications where users interact with‬
‭data in real time, and databases are used to store and manage that data.‬
mysql-connector-python‬
‭Libraries such as‬‭ PyMySQL‬
‭,‬‭ ‭,‬‭and‬
‭QLAlchemy‬‭allow Python applications to connect with‬‭MySQL databases‬
S
‭and perform these operations seamlessly.‬

‭ ySQL is one of the most popular relational database management‬


M
‭systems, and Python, being a versatile and user-friendly programming‬
‭language, complements it perfectly for building scalable and robust‬
‭applications. By connecting Python to MySQL, developers can leverage the‬
‭full power of SQL queries alongside Python’s flexibility, enabling efficient‬
‭data handling and management.‬

‭Why Use Python MySQL Connectivity?‬

‭9‬
‭ ython MySQL connectivity is useful for a variety of reasons, especially‬
P
‭when developing applications that require interaction with large datasets or‬
‭real-time data. Here are some key advantages of using Python to connect‬
‭with MySQL:‬

‭1.‬ ‭Dynamic Applications‬‭:‬


‭○‬ ‭Python's ability to connect to MySQL enables the creation of‬
‭dynamic, real-time applications. For example, e-commerce‬
‭platforms, inventory management systems, and user‬
‭authentication systems all rely heavily on the interaction‬
‭between an application and a database. Using Python with‬
‭MySQL, developers can query the database in real time to‬
‭update stock levels, authenticate users, or display dynamic data‬
‭on a website.‬
‭2.‬ ‭Automation‬‭:‬
‭○‬ ‭Python makes it easy to automate repetitive tasks related to‬
‭database management. Tasks like backups, updates, and‬
‭monitoring of MySQL databases can be automated through‬
‭Python scripts. This reduces the chances of human error and‬
‭saves a significant amount of time for developers and database‬
‭administrators.‬
‭3.‬ ‭Scalability‬‭:‬
‭○‬ ‭Both Python and MySQL are known for their scalability. As your‬
‭application grows, you can rely on Python’s efficiency in‬
‭handling large amounts of data, combined with MySQL’s‬
‭powerful query capabilities, to manage larger databases without‬
‭losing performance. Python’s ease of use and MySQL’s‬
‭powerful features make them a perfect combination for scalable‬
‭applications.‬
‭4.‬ ‭Ease of Use‬‭:‬
‭○‬ ‭Python’s simple and readable syntax makes it an excellent‬
‭choice for interacting with MySQL databases. The language‬
‭allows developers to easily write SQL queries, manage‬
‭connections, and handle exceptions in a clean and‬
‭understandable way. For those already familiar with Python,‬

‭10‬
i‭ntegrating MySQL into their applications is a straightforward‬
‭process.‬

‭Steps for Python MySQL Connectivity‬


‭ onnecting Python to MySQL involves several steps, including installing‬
C
‭necessary software and libraries, establishing a connection, executing‬
‭queries, and handling results. Here’s a brief overview of these steps:‬

‭1.‬ ‭Install MySQL Server‬‭:‬


‭○‬ ‭The first step is to set up MySQL on your system or use a‬
‭hosted MySQL service. After installation, create the necessary‬
‭databases and tables for your application. For example, you‬
‭may create a database for inventory management, including‬
‭tables for products, users, and transactions.‬
‭2.‬ ‭Install MySQL Connector‬‭:‬
‭○‬ ‭Python needs a connector to interact with MySQL. The most‬
‭commonly used library for this purpose is‬
mysql-connector-python‬
‭ ‭. This can be installed via‬‭the‬
pip install‬
‭Python package manager (pip). The command‬‭
‭ysql-connector-python‬‭will install the connector‬‭and‬
m
‭allow Python to communicate with MySQL.‬
‭3.‬ ‭Establish Connection‬‭:‬
‭○‬ ‭Once the connector is installed, you can establish a connection‬
‭to your MySQL database. This involves specifying connection‬
‭parameters like host (e.g., localhost), user (e.g., root),‬
‭password, and the database you want to work with. The‬
mysql.connector.connect()‬‭method is used to initiate‬‭the‬

‭connection.‬
‭4.‬ ‭Execute SQL Queries‬‭:‬
‭○‬ ‭After establishing a connection, you can use Python to send‬
‭SQL queries to MySQL. For example, you can use SQL‬
SELECT‬‭to retrieve data,‬‭
‭commands like‬‭ INSERT‬‭to add‬‭new‬
UPDATE‬‭to modify data, or‬‭
‭data,‬‭ DELETE‬‭to remove data.‬

‭11‬
‭ ython sends these queries through the cursor object to‬
P
‭MySQL for execution.‬
‭5.‬ ‭Handle Results‬‭:‬
‭○‬ ‭After executing a query, you will need to process the results.‬
SELECT‬‭queries, this means fetching the rows returned‬‭by‬
‭For‬‭
fetchall()‬‭to‬
‭the database. Python provides methods like‬‭
fetchone()‬‭to retrieve a single‬‭row.‬
r‭ etrieve all rows or‬‭
‭6.‬ ‭Close the Connection‬‭:‬
‭○‬ ‭It is essential to close the database connection once your‬
‭operations are complete. This ensures that resources are freed‬
‭and that the application does not consume unnecessary‬
‭resources while idle.‬

‭Key Concepts in Python MySQL Connectivity‬


‭ o interact with MySQL through Python, you need to understand a few key‬
T
‭concepts:‬

‭1.‬ ‭Connection‬‭:‬
‭○‬ ‭Python establishes a connection to MySQL using the‬
mysql.connector.connect()‬‭method. The connection‬

‭requires essential parameters such as the host, username,‬
‭password, and database name. Once the connection is‬
‭established, Python can communicate with the MySQL‬
‭database.‬
‭2.‬ ‭Cursor Object‬‭:‬
‭○‬ ‭The cursor is an object that allows Python to execute SQL‬
‭commands. The cursor sends commands to the database and‬
‭retrieves results. It acts as an intermediary between Python and‬
‭MySQL. Using the cursor, you can run SQL queries and‬
‭process the returned data.‬
‭3.‬ ‭SQL Execution‬‭:‬
‭○‬ ‭To run SQL queries, you use the‬‭ cursor.execute()‬‭method.‬
‭This method sends a SQL statement to MySQL, where it is‬

‭12‬
‭ xecuted. You can use this method to execute various SQL‬
e
‭commands such as‬‭ INSERT‬ SELECT‬
‭,‬‭ UPDATE‬
‭,‬‭ DELETE‬
‭, and‬‭ ‭.‬
‭4.‬ ‭Fetch Data‬‭:‬
SELECT‬‭query, you can use methods‬‭like‬
‭○‬ ‭After executing a‬‭
‭ursor.fetchall()‬‭to retrieve the results. This method‬
c
‭returns all the rows from the query result. Alternatively, you can‬
‭use‬‭ cursor.fetchone()‬‭to fetch a single row.‬
‭5.‬ ‭Error Handling‬‭:‬
‭○‬ ‭Proper error handling is crucial in database interactions to‬
‭ensure the application runs smoothly. Python provides the‬
try-except‬‭block, which helps catch any exceptions‬‭that‬

‭might arise during the connection or query execution. This‬
‭ensures that your application doesn’t crash due to unexpected‬
‭errors.‬

‭Common MySQL Operations with Python‬


‭1.‬ ‭Create Table‬‭:‬
‭○‬ ‭You can use Python to create tables in MySQL. The SQL‬
‭command‬‭ CREATE TABLE‬‭allows you to define the structure‬‭of‬
‭the data in the database. For example, you may create a‬
products‬‭table with fields like product name, price,‬‭and stock‬

‭quantity.‬
‭2.‬ ‭Insert Data‬‭:‬
‭○‬ ‭The‬‭ INSERT INTO‬‭SQL command is used to add new records‬
‭to a table. Python can automate the process of adding new‬
‭records by executing this command with appropriate values.‬
‭3.‬ ‭Retrieve Data‬‭:‬
‭○‬ ‭The‬‭ SELECT‬‭statement is used to retrieve data from‬‭MySQL.‬
‭Using Python, you can dynamically fetch data based on user‬
‭inputs or other application logic.‬
‭4.‬ ‭Update Data‬‭:‬

‭13‬
‭○‬ Y ‭ ou can update existing data in a table using the‬‭ UPDATE‬
‭statement. This is useful for modifying values based on specific‬
‭conditions.‬
‭5.‬ ‭Delete Data‬‭:‬
‭○‬ ‭The‬‭ DELETE‬‭statement is used to remove data from the‬
‭database. You can use Python to delete records based on‬
‭specific conditions, such as removing outdated inventory items‬
‭or inactive users.‬
‭6.‬ ‭Close Connection‬‭:‬
‭○‬ ‭After all operations are completed, you should close the‬
‭database connection using‬‭ connection.close()‬ ‭. This‬
‭ensures the proper release of resources and prevents memory‬
‭leaks.‬

‭Benefits of Python MySQL Connectivity‬


‭1.‬ ‭Easy Integration‬‭:‬
‭○‬ ‭Python’s simple syntax makes it easy to integrate with MySQL,‬
‭allowing developers to interact with databases without a steep‬
‭learning curve.‬
‭2.‬ ‭Efficient Data Handling‬‭:‬
‭○‬ ‭Python’s flexibility and MySQL’s powerful querying capabilities‬
‭allow efficient handling of both small and large datasets.‬
‭3.‬ ‭Scalability‬‭:‬
‭○‬ ‭Python and MySQL are both highly scalable, making them ideal‬
‭for applications that need to grow and handle increasing‬
‭amounts of data.‬
‭4.‬ ‭Error Handling‬‭:‬
‭○‬ ‭Python provides robust error handling, ensuring that any issues‬
‭with the database connection or query execution can be‬
‭managed without crashing the application.‬
‭5.‬ ‭Automation‬‭:‬
‭○‬ ‭With Python, you can automate repetitive database tasks like‬
‭backups, maintenance, and updates, saving time and ensuring‬
‭consistency.‬

‭14‬
‭Conclusion‬
‭ ython MySQL connectivity is an essential skill for developers working on‬
P
‭data-driven applications. By leveraging libraries like‬
mysql-connector-python‬
‭ ‭, Python can interact with MySQL‬‭databases‬
‭and perform various operations efficiently. This integration allows‬
‭developers to create dynamic, real-time applications, automate database‬
‭tasks, and handle large-scale data with ease. Whether you're building a‬
‭simple project or a large, complex system, Python’s connection to MySQL‬
‭provides the tools needed to manage and manipulate data effectively.‬

‭15‬
‭ escription of the Airline Management‬
D
‭System‬
‭ his code implements a basic text-based Airline Management System‬
T
‭(AMS) in Python, using MySQL as the database backend. The primary‬
‭objective of the system is to manage flights, passengers, bookings, and‬
‭crew information in an airline setting. The system provides user‬
‭management, flight booking, and administrative functionalities in a console‬
‭application format. The database schema stores all relevant data such as‬
‭flight details, passenger information, crew roles, booking data, and user‬
‭credentials.‬

‭Database Setup and Structure‬


‭ he first step in the program is setting up a MySQL database and tables‬
T
‭that will store all relevant data. It connects to MySQL using the‬
mysql.connector‬‭package, prompting the user for the‬‭root password,‬

‭and establishes a connection. Once connected, the following steps are‬
‭performed:‬

‭1.‬ ‭Database Creation:‬


‭○‬ ‭A database named‬‭ airline_management‬‭is created if‬‭it‬
‭doesn’t already exist.‬
‭2.‬ ‭Table Creation:‬
‭○‬ ‭The system ensures that five essential tables are created if they‬
‭are missing. These tables are:‬
‭■‬ ‭flights‬‭: Stores flight details, including flight number,‬
‭source, destination, departure and arrival times, and the‬
‭price of the ticket.‬
‭■‬ ‭passengers‬‭: Contains passenger information such as‬
‭their name, age, gender, and contact details.‬
‭■‬ ‭bookings‬‭: Links passengers to flights, with a seat‬
‭number assigned to each booking. This table uses foreign‬
passengers‬‭and‬‭
‭keys to link to the‬‭ flights‬‭tables.‬

‭16‬
‭■‬ c ‭ rew‬‭: Stores information about the flight crew (e.g., pilot,‬
‭co-pilot, cabin crew) and links them to specific flights via‬
‭the‬‭flight_id‬ ‭.‬
‭■‬ ‭users‬‭: Holds the credentials of users of the system.‬‭Each‬
‭user has a unique‬‭ username‬‭and a‬‭password‬‭that are‬
‭used for authentication.‬

‭ hese tables facilitate the management of the airline’s operations, including‬


T
‭flight schedules, crew assignments, and passenger bookings. By having‬
‭relational tables, the system efficiently organizes the data in a normalized‬
‭format that ensures consistency and reduces redundancy.‬

‭User Management‬
‭Sign Up Functionality‬

‭ he system allows users to sign up for an account to access the‬


T
‭application. This is handled in the‬‭ sign_up()‬‭function.‬‭The user is‬
‭prompted to provide a username and a password. The system checks if the‬
‭username already exists in the‬‭ users‬‭table before‬‭inserting a new user‬
‭record. If the username exists, the system alerts the user and asks for a‬
‭different username. If the username is available, the new account is‬
‭created and saved to the‬‭users‬‭table, ensuring the‬‭password is stored in‬
‭plain text.‬

‭●‬ ‭Step-by-step sign-up process‬‭:‬


‭1.‬ ‭Prompt for a new username and password.‬
‭2.‬ ‭Check if the username already exists in the‬‭ users‬‭table.‬
‭3.‬ ‭If the username exists, notify the user and ask for another.‬
‭4.‬ ‭If the username is new, create a new record in the database.‬

‭Log In Functionality‬

‭17‬
‭ nce users have signed up, they can log in to access the airline‬
O
‭management system. In the‬‭ login()‬‭function, users enter their username‬
‭and password. The system checks whether the provided credentials match‬
‭a record in the‬‭users‬‭table. If the credentials are‬‭valid, the user is granted‬
‭access to the main menu; otherwise, an error message is shown, and the‬
‭user is prompted to try again.‬

‭●‬ ‭Step-by-step log-in process‬‭:‬


‭1.‬ ‭Prompt for a username and password.‬
users‬‭table.‬
‭2.‬ ‭Validate the credentials by querying the‬‭
‭3.‬ ‭If valid, proceed to the main menu; otherwise, display an error.‬

‭Main Menu Navigation‬


‭ fter a successful login, users are presented with the main menu, which‬
A
‭provides options to manage different aspects of the airline system. The‬
‭menu includes:‬

‭ .‬ ‭Manage Flights‬‭: Options to add, view, or delete flights.‬


1
‭2.‬ ‭Manage Passengers‬‭: Add, view, and manage passenger‬‭details.‬
‭3.‬ ‭Manage Bookings‬‭: Add bookings, view, or manage flight‬
‭reservations.‬
‭4.‬ ‭Manage Crew‬‭: Add crew members and view crew assignments.‬
‭5.‬ ‭Log Out‬‭: Exit the system.‬

‭ ach menu option corresponds to a specific function, providing the user‬


E
‭with control over different aspects of airline operations. The menu ensures‬
‭that only authorized users (those who have logged in) can interact with the‬
‭system, and it allows the user to navigate between different management‬
‭areas.‬

‭Flight Management‬

‭18‬
‭ he‬‭
T manage_flights()‬‭function allows users to add new flights, view all‬
‭flights, and delete existing ones. The flight details include:‬

‭‬
● ‭ light number‬‭: A unique identifier for the flight.‬
F
‭●‬ ‭Source and Destination‬‭: The origin and destination‬‭airports.‬
‭●‬ ‭Departure and Arrival times‬‭: The flight's schedule.‬
‭●‬ ‭Price‬‭: The ticket price for the flight.‬

‭Add Flight:‬

‭●‬ T ‭ he system prompts the user for the flight number, source,‬
‭destination, departure and arrival times, and price.‬
‭●‬ ‭These details are then inserted into the‬‭flights‬‭table.‬

‭View Flights:‬

‭●‬ T flights‬
‭ he system retrieves and displays all flight records from the‬‭
‭table.‬

‭Delete Flight:‬

‭●‬ T
‭ he user can delete a flight by providing the flight ID. This action‬
‭removes the corresponding record from the‬‭ flights‬‭table.‬

‭Passenger Management‬

manage_passengers()‬‭function is used to manage‬‭passenger‬


‭ he‬‭
T
‭details. Users can add passengers or view all existing passenger records.‬

‭Add Passenger:‬

‭●‬ U ‭ sers are prompted to enter passenger details such as name, age,‬
‭gender, and mobile number.‬
passengers‬‭table.‬
‭●‬ ‭These details are stored in the‬‭

‭View Passengers:‬

‭19‬
‭●‬ T
‭ he system fetches all passenger records from the database and‬
‭displays them to the user.‬

‭Booking Management‬

‭ he‬‭
T manage_bookings()‬‭function handles booking operations,‬‭allowing‬
‭users to add, view, or delete bookings. A booking is a reservation made by‬
‭a passenger on a specific flight.‬

‭Add Booking:‬

‭‬ T
● ‭ he system asks for the passenger's ID, flight ID, and seat number.‬
bookings‬‭table.‬
‭●‬ ‭This information is stored in the‬‭

‭View Bookings:‬

bookings‬‭table.‬
‭●‬ ‭The user can view all bookings from the‬‭

‭Crew Management‬

manage_crew()‬‭function handles crew assignments.‬‭Users can add‬


‭ he‬‭
T
‭new crew members and view their roles for each flight.‬

‭Add Crew Member:‬

‭●‬ T ‭ he user is prompted to enter the crew member's name, role (e.g.,‬
‭Pilot, Co-Pilot, Cabin Crew), and the associated flight ID.‬
‭●‬ ‭These details are added to the‬‭ crew‬‭table.‬

‭View Crew Members:‬

‭●‬ T
‭ he system displays all crew members and their roles, as stored in‬
crew‬‭table.‬
‭the‬‭

‭20‬
‭Booking and Cancellation for Passengers‬
‭ he system also allows passengers to book flights and cancel existing‬
T
‭bookings via the following functions:‬

‭Book Flight:‬

‭●‬ A ‭ passenger can book a flight by providing their name. The system‬
passengers‬‭table.‬
‭first checks if the passenger exists in the‬‭
‭●‬ ‭If the passenger exists, the system fetches all available flights and‬
‭allows the passenger to choose a flight and seat number.‬
‭●‬ ‭The booking is then added to the‬‭ bookings‬‭table.‬

‭Cancel Booking:‬

‭●‬ A
‭ passenger can cancel an existing booking by providing their name.‬
‭The system checks for any existing bookings and allows the‬
‭cancellation of a selected booking.‬

‭Conclusion‬
‭ he Airline Management System provides a comprehensive and interactive‬
T
‭interface for managing flights, passengers, bookings, and crew members. It‬
‭also includes user authentication and a basic menu-driven interface for‬
‭easy navigation. The system stores all data in a MySQL database, which is‬
‭structured into relational tables to ensure data consistency and easy‬
‭retrieval. This system can be extended further by adding more advanced‬
‭features such as flight search functionality, dynamic pricing, and role-based‬
‭access control for administrators and regular users.‬

‭21‬
‭ o run the‬‭Airline Management System‬‭(AMS) effectively, both hardware‬
T
‭and software components are required. Below is a breakdown of the‬
‭hardware‬‭and‬‭software‬‭requirements needed to set up‬‭and operate the‬
‭AMS.‬

‭Hardware Requirements:‬
‭1.‬ ‭Processor (CPU):‬
‭○‬ ‭A modern multi-core processor (Intel i3, i5, i7, or AMD Ryzen)‬
‭should be sufficient for this application, as the AMS is primarily‬
‭a text-based system and does not require heavy computational‬
‭power.‬
‭○‬ ‭Recommended: Intel Core i5 or higher for smooth performance.‬
‭2.‬ ‭Memory (RAM):‬
‭○‬ ‭At least 4 GB of RAM is required for basic operation. However,‬
‭for better performance, especially if the system grows and‬
‭handles more data, 8 GB or more would be ideal.‬
‭○‬ ‭Recommended: 8 GB of RAM or more.‬
‭3.‬ ‭Storage:‬
‭○‬ ‭A hard drive or SSD with sufficient space to store the database,‬
‭application files, and logs.‬
‭○‬ ‭At least 20 GB of free space is recommended for a small-scale‬
‭implementation. Larger data storage will be required as the‬
‭system grows (with multiple users and flight records).‬
‭○‬ ‭Recommended: 250 GB SSD (Solid State Drive) or more for‬
‭faster read/write performance.‬
‭4.‬ ‭Database Server:‬
‭○‬ ‭MySQL Server‬‭or similar relational database management‬
‭system (RDBMS) installed on either the same machine or a‬
‭dedicated server, depending on the scale of the operations.‬
‭○‬ ‭The system can run on either a local server for small-scale‬
‭usage or a cloud-based server for scalability and accessibility.‬
‭5.‬ ‭Networking:‬

‭22‬
‭○‬ I‭f you are using a local database server or multiple users are‬
‭accessing the system, a reliable network connection (Ethernet‬
‭or Wi-Fi) is necessary.‬
‭○‬ ‭Internet connectivity is also required for updates, access to‬
‭cloud services, or integrating third-party APIs.‬
‭6.‬ ‭Display:‬
‭○‬ ‭A standard monitor (minimum resolution of 1366x768) is‬
‭sufficient for text-based interaction. However, a larger and‬
‭higher resolution display will enhance user experience,‬
‭especially for administrative tasks.‬
‭7.‬ ‭Keyboard and Mouse:‬
‭○‬ ‭Basic input peripherals (keyboard and mouse) are required for‬
‭navigation and interaction with the application.‬

‭Software Requirements:‬
‭1.‬ ‭Operating System:‬
‭○‬ ‭The AMS is compatible with most major operating systems,‬
‭including:‬
‭■‬ ‭Windows (7 or newer)‬‭: For users who prefer a‬
‭Windows-based environment.‬
‭■‬ ‭Linux (Ubuntu/Debian/CentOS)‬‭: For users who prefer‬
‭an open-source server environment.‬
‭■‬ ‭macOS‬‭: For Apple users.‬
‭○‬ ‭Recommended: Windows 10 or Linux Ubuntu for ease of‬
‭installation and support.‬
‭2.‬ ‭Programming Language:‬
‭○‬ ‭Python‬‭: The primary language used for developing the‬‭Airline‬
‭Management System.‬
‭○‬ ‭Version: Python 3.x (Preferably Python 3.6 or higher for better‬
‭compatibility with libraries).‬
‭3.‬ ‭Database:‬

‭23‬
‭○‬ M ‭ ySQL‬‭: The database system used to store all the airline data‬
‭(e.g., flights, passengers, bookings).‬
‭○‬ ‭MySQL Workbench or any similar database management tool‬
‭can be used for easier database management, queries, and‬
‭administration.‬
‭○‬ ‭MariaDB‬‭can be an alternative to MySQL if needed.‬
‭4.‬ ‭Integrated Development Environment (IDE):‬
‭○‬ ‭Visual Studio Code‬‭: A powerful and lightweight editor‬‭for‬
‭writing Python code.‬
‭○‬ ‭PyCharm‬‭: A feature-rich IDE specifically for Python‬
‭development.‬
‭○‬ ‭Atom‬‭or‬‭Sublime Text‬‭: Lightweight and fast text editors‬‭for‬
‭Python development.‬
‭5.‬ ‭Required Python Libraries/Packages:‬
‭○‬ ‭mysql-connector-python‬‭: For connecting Python with‬‭MySQL‬
‭databases.‬
‭○‬ ‭Tkinter‬‭(optional): If you plan to develop a graphical‬‭user‬
‭interface (GUI) version of the AMS.‬
‭○‬ ‭pandas‬‭(optional): For advanced data manipulation‬‭and‬
‭reporting.‬
‭○‬ ‭datetime‬‭: To handle date and time operations (for‬‭flight‬
‭schedules).‬
‭6.‬ ‭Database Management Tool (optional but recommended):‬
‭○‬ ‭MySQL Workbench‬‭: To visualize the database structure,‬‭run‬
‭queries, and manage the MySQL server.‬
‭○‬ ‭phpMyAdmin‬‭(web-based tool): If you prefer managing‬‭your‬
‭MySQL database via a browser interface.‬
‭7.‬ ‭Web Browser‬‭(if deploying the system online):‬
‭○‬ ‭Any modern browser (Chrome, Firefox, Safari) for accessing‬
‭and interacting with the web-based user interface (if applicable).‬
‭8.‬ ‭Security Software:‬
‭○‬ ‭Antivirus Software‬‭: Ensure that the system is secure‬‭from‬
‭malicious attacks and infections.‬

‭24‬
‭○‬ F ‭ irewall‬‭: Protect the system from unauthorized access,‬
‭especially if the AMS is deployed in a multi-user environment or‬
‭cloud server.‬
‭○‬ ‭SSL Certificates‬‭: If deploying the AMS on the web,‬‭SSL‬
‭certificates are required for secure connections.‬

‭Additional Optional Components:‬


‭1.‬ ‭Web Framework (Optional for Web Deployment):‬
‭○‬ ‭Flask‬‭or‬‭Django‬‭: If you plan to deploy the AMS as‬‭a web‬
‭application, these frameworks can be used to create a web‬
‭interface for the AMS, making it more user-friendly and‬
‭accessible over the internet.‬
‭2.‬ ‭Cloud Hosting (Optional for Scalability):‬
‭○‬ ‭Amazon Web Services (AWS)‬‭,‬‭Microsoft Azure‬‭, or‬‭Google‬
‭Cloud Platform (GCP)‬‭: If the system needs to scale‬‭for‬
‭multiple users or handle large amounts of data, cloud hosting‬
‭services are a good option.‬
‭○‬ ‭Heroku‬‭: A platform-as-a-service (PaaS) for easy deployment‬‭of‬
‭applications, including Python-based systems.‬
‭3.‬ ‭Backup Software (Optional but recommended):‬
‭○‬ ‭Regular backups of the database and the system should be‬
‭performed using tools like‬‭mysqldump‬‭or other database‬
‭backup solutions to prevent data loss.‬

‭Summary:‬
‭ o run and manage the Airline Management System, you will need a‬
T
‭standard computer or server with sufficient processing power (Intel i5 or‬
‭better), at least 4 GB of RAM, and adequate storage (SSD recommended).‬
‭The system requires Python 3.x, MySQL for database management, and‬
mysql-connector-python‬‭for‬
‭various Python libraries such as‬‭

‭25‬
c‭ onnecting to the database. A web browser and database management‬
‭tools like MySQL Workbench are recommended for easier management.‬
‭Depending on the scale and deployment needs, optional components like a‬
‭web framework, cloud hosting, and backup software can be incorporated.‬

‭26‬
‭SOURCE CODE‬

‭27‬
‭import mysql.connector as ms‬

‭print("""‬
‭==================================‬
‭Welcome to Airline System‬
‭==================================‬
‭""")‬

‭ Establishing connection and creating database with required tables‬


#
‭password = input("Enter MySQL root password: ")‬

‭ n = ms.connect(host="localhost", user="root", passwd=password)‬


c
‭cur = cn.cursor()‬

‭ Creating database and tables‬


#
‭cur.execute("CREATE DATABASE IF NOT EXISTS airline_management")‬
‭cur.execute("USE airline_management")‬

‭ ur.execute("""‬
c
‭CREATE TABLE IF NOT EXISTS flights (‬
‭flight_id INT AUTO_INCREMENT PRIMARY KEY,‬
‭flight_number VARCHAR(10) NOT NULL,‬
‭source VARCHAR(50),‬
‭destination VARCHAR(50),‬
‭departure_time DATETIME,‬
‭arrival_time DATETIME,‬
‭price DECIMAL(10, 2)‬
‭)‬
‭""")‬

‭ ur.execute("""‬
c
‭CREATE TABLE IF NOT EXISTS passengers (‬
‭passenger_id INT AUTO_INCREMENT PRIMARY KEY,‬
‭name VARCHAR(50),‬
‭age INT,‬
‭gender VARCHAR(10),‬
‭mobile VARCHAR(15)‬

‭28‬
)‭ ‬
‭""")‬

‭ ur.execute("""‬
c
‭CREATE TABLE IF NOT EXISTS bookings (‬
‭booking_id INT AUTO_INCREMENT PRIMARY KEY,‬
‭passenger_id INT,‬
‭flight_id INT,‬
‭seat_number VARCHAR(5),‬
‭FOREIGN KEY (passenger_id) REFERENCES‬
‭passengers(passenger_id),‬
‭FOREIGN KEY (flight_id) REFERENCES flights(flight_id)‬
‭)‬
‭""")‬

‭ ur.execute("""‬
c
‭CREATE TABLE IF NOT EXISTS crew (‬
‭crew_id INT AUTO_INCREMENT PRIMARY KEY,‬
‭name VARCHAR(50),‬
‭role VARCHAR(20),‬
‭flight_id INT,‬
‭FOREIGN KEY (flight_id) REFERENCES flights(flight_id)‬
‭)‬
‭""")‬

‭ ur.execute("""‬
c
‭CREATE TABLE IF NOT EXISTS users (‬
‭username VARCHAR(30) PRIMARY KEY,‬
‭password VARCHAR(30)‬
‭)‬
‭""")‬

‭cn.commit()‬

‭def sign_up():‬
‭print("\n======= Sign Up =======")‬
‭username = input("Enter new username: ")‬

‭29‬
‭password = input("Enter new password: ")‬

‭ ur.execute("SELECT * FROM users WHERE username = %s",‬


c
‭(username,))‬
‭existing_user = cur.fetchone()‬

i‭f existing_user:‬
‭print("Username already taken, please choose a different username.")‬
‭else:‬
‭try:‬
‭cur.execute("INSERT INTO users (username, password) VALUES (%s,‬
‭%s)", (username, password))‬
‭cn.commit()‬
‭print("User created successfully!")‬
‭except ms.Error as e:‬
‭print(f"Error: {e}")‬

‭def login():‬
‭print("\n======= Log In =======")‬
‭username = input("Enter username: ")‬
‭password = input("Enter password: ")‬
‭cur.execute("SELECT * FROM users WHERE username = %s AND‬
‭password = %s", (username, password))‬
‭user = cur.fetchone()‬
‭if user:‬
‭print("Login successful!")‬
‭main_menu()‬
‭else:‬
‭print("Invalid credentials.")‬

‭def main_menu():‬
‭while True:‬
‭print("""‬
‭1. Manage Flights‬
‭2. Manage Passengers‬
‭3. Manage Bookings‬
‭4. Manage Crew‬

‭30‬
‭ . Log Out‬
5
‭""")‬
‭choice = input("Enter your choice: ")‬
‭if choice == '1':‬
‭manage_flights()‬
‭elif choice == '2':‬
‭manage_passengers()‬
‭elif choice == '3':‬
‭manage_bookings()‬
‭elif choice == '4':‬
‭manage_crew()‬
‭elif choice == '5':‬
‭print("Logged out.")‬
‭break‬
‭else:‬
‭print("Invalid choice.")‬

‭def manage_flights():‬
‭print("\n======= Manage Flights =======")‬
‭while True:‬
‭print("""‬
‭1. Add Flight‬
‭2. View Flights‬
‭3. Delete Flight‬
‭4. Back to Main Menu‬
‭""")‬
‭choice = input("Enter your choice: ")‬
‭if choice == '1':‬
‭flight_number = input("Enter flight number: ")‬
‭source = input("Enter source: ")‬
‭destination = input("Enter destination: ")‬
‭departure_time = input("Enter departure time (YYYY-MM-DD HH:MM:SS):‬
‭")‬
‭arrival_time = input("Enter arrival time (YYYY-MM-DD HH:MM:SS): ")‬
‭price = input("Enter price: ")‬
‭cur.execute("INSERT INTO flights (flight_number, source, destination,‬
‭departure_time, arrival_time, price) VALUES (%s, %s, %s, %s, %s, %s)",‬

‭31‬
(‭ flight_number, source, destination, departure_time,‬
‭arrival_time, price))‬
‭cn.commit()‬
‭print("Flight added successfully!")‬
‭elif choice == '2':‬
‭cur.execute("SELECT * FROM flights")‬
‭flights = cur.fetchall()‬
‭for flight in flights:‬
‭print(flight)‬
‭elif choice == '3':‬
‭flight_id = input("Enter flight ID to delete: ")‬
‭cur.execute("DELETE FROM flights WHERE flight_id = %s", (flight_id,))‬
‭cn.commit()‬
‭print("Flight deleted successfully!")‬
‭elif choice == '4':‬
‭break‬
‭else:‬
‭print("Invalid choice.")‬

‭def manage_passengers():‬
‭print("\n======= Manage Passengers =======")‬
‭while True:‬
‭print("""‬
‭1. Add Passenger‬
‭2. View Passengers‬
‭3. Back to Main Menu‬
‭""")‬
‭choice = input("Enter your choice: ")‬
‭if choice == '1':‬
‭name = input("Enter passenger name: ")‬
‭age = input("Enter age: ")‬
‭gender = input("Enter gender: ")‬
‭mobile = input("Enter mobile number: ")‬
‭cur.execute("INSERT INTO passengers (name, age, gender, mobile)‬
‭VALUES (%s, %s, %s, %s)",‬
‭(name, age, gender, mobile))‬
‭cn.commit()‬

‭32‬
‭ rint("Passenger added successfully!")‬
p
‭elif choice == '2':‬
‭cur.execute("SELECT * FROM passengers")‬
‭passengers = cur.fetchall()‬
‭for passenger in passengers:‬
‭print(passenger)‬
‭elif choice == '3':‬
‭break‬
‭else:‬
‭print("Invalid choice.")‬

‭def manage_bookings():‬
‭print("\n======= Manage Bookings =======")‬
‭while True:‬
‭print("""‬
‭1. Add Booking‬
‭2. View Bookings‬
‭3. Back to Main Menu‬
‭""")‬
‭choice = input("Enter your choice: ")‬
‭if choice == '1':‬
‭passenger_id = input("Enter passenger ID: ")‬
‭flight_id = input("Enter flight ID: ")‬
‭seat_number = input("Enter seat number: ")‬
‭cur.execute("INSERT INTO bookings (passenger_id, flight_id,‬
‭seat_number) VALUES (%s, %s, %s)",‬
‭(passenger_id, flight_id, seat_number))‬
‭cn.commit()‬
‭print("Booking added successfully!")‬
‭elif choice == '2':‬
‭cur.execute("SELECT * FROM bookings")‬
‭bookings = cur.fetchall()‬
‭for booking in bookings:‬
‭print(booking)‬
‭elif choice == '3':‬
‭break‬
‭else:‬

‭33‬
‭print("Invalid choice.")‬

‭def manage_crew():‬
‭print("\n======= Manage Crew =======")‬
‭while True:‬
‭print("""‬
‭1. Add Crew Member‬
‭2. View Crew Members‬
‭3. Back to Main Menu‬
‭""")‬
‭choice = input("Enter your choice: ")‬
‭if choice == '1':‬
‭name = input("Enter crew name: ")‬
‭role = input("Enter role (Pilot/Co-Pilot/Cabin Crew): ")‬
‭flight_id = input("Enter flight ID: ")‬
‭cur.execute("INSERT INTO crew (name, role, flight_id) VALUES (%s, %s,‬
‭%s)",‬
‭(name, role, flight_id))‬
‭cn.commit()‬
‭print("Crew member added successfully!")‬
‭elif choice == '2':‬
‭cur.execute("SELECT * FROM crew")‬
‭crew_members = cur.fetchall()‬
‭for member in crew_members:‬
‭print(member)‬
‭elif choice == '3':‬
‭break‬
‭else:‬
‭print("Invalid choice.")‬

‭def book_flight():‬
‭print("\n======= Book a Flight =======")‬
‭name = input("Enter your name: ")‬
‭cur.execute("SELECT passenger_id FROM passengers WHERE name =‬
‭%s", (name,))‬
‭passenger = cur.fetchone()‬
‭if not passenger:‬

‭34‬
‭ rint("Passenger not found. Please register first.")‬
p
‭return‬
‭passenger_id = passenger[0]‬
‭cur.execute("SELECT * FROM flights")‬
‭flights = cur.fetchall()‬
‭for flight in flights:‬
‭print(flight)‬
‭flight_id = input("Enter flight ID to book: ")‬
‭seat_number = input("Enter seat number: ")‬
‭cur.execute("INSERT INTO bookings (passenger_id, flight_id,‬
‭seat_number) VALUES (%s, %s, %s)",‬
‭(passenger_id, flight_id, seat_number))‬
‭cn.commit()‬
‭print("Booking successful!")‬

‭def cancel_booking():‬
‭print("\n======= Cancel Booking =======")‬
‭name = input("Enter your name: ")‬
‭cur.execute("SELECT passenger_id FROM passengers WHERE name =‬
‭%s", (name,))‬
‭passenger = cur.fetchone()‬
‭if not passenger:‬
‭print("Passenger not found.")‬
‭return‬
‭passenger_id = passenger[0]‬
‭cur.execute("SELECT * FROM bookings WHERE passenger_id = %s",‬
‭(passenger_id,))‬
‭bookings = cur.fetchall()‬
‭for booking in bookings:‬
‭print(booking)‬
‭booking_id = input("Enter booking ID to cancel: ")‬
‭cur.execute("DELETE FROM bookings WHERE booking_id = %s AND‬
‭passenger_id = %s", (booking_id, passenger_id))‬
‭cn.commit()‬
‭print("Booking cancelled.")‬

‭def view_my_bookings():‬

‭35‬
‭ rint("\n======= My Bookings =======")‬
p
‭name = input("Enter your name: ")‬
‭cur.execute("SELECT passenger_id FROM passengers WHERE name =‬
‭%s", (name,))‬
‭passenger = cur.fetchone()‬
‭if not passenger:‬
‭print("Passenger not found.")‬
‭return‬
‭passenger_id = passenger[0]‬
‭cur.execute("SELECT * FROM bookings WHERE passenger_id = %s",‬
‭(passenger_id,))‬
‭bookings = cur.fetchall()‬
‭for booking in bookings:‬
‭print(booking)‬

‭ Main Menu‬
#
‭while True:‬
‭print("""‬
‭1. Sign Up‬
‭2. Log In‬
‭3. Exit‬
‭""")‬
‭choice = input("Enter your choice: ")‬
‭if choice == '1':‬
‭sign_up()‬
‭elif choice == '2':‬
‭login()‬
‭elif choice == '3':‬
‭print("Thank you for using the Airline Management System!")‬
‭break‬
‭else:‬
‭print("Invalid choice.")‬

‭36‬
‭37‬
‭OUTPUT‬

‭38‬
‭Airline Management System – Front-End Workflow‬
‭1. User Authentication‬

‭When you first run the program, you'll need to log in or sign up.‬

‭Option 1: Sign Up (Create a New User Account)‬

‭This creates a new user and stores their credentials in the system.‬

‭Option 2: Log In with Existing Credentials‬

‭If the credentials match, you will be logged in successfully.‬

‭2. Managing Flights (Admin Section)‬

‭Option 1: Add a New Flight‬

‭39‬
‭●‬ A
‭ fter logging in, if you are an admin, you can manage flights by adding‬
‭new flights with the following prompt:‬

‭The system will then execute the SQL query to add this flight to the database.‬

‭Output:‬

‭Option 2: View All Flights‬

‭ ou can view all the flights available by selecting the “View All Flights” option.‬
Y
‭The system will display all flights from the database, such as:‬

‭Option 3: Delete a Flight‬

I‭f an admin wants to delete a flight, they can select a flight ID from the list of‬
‭flights and enter it.‬

‭40‬
‭This will remove the flight from the database and confirm the deletion:‬

‭3. Managing Passengers (Admin Section)‬

‭Option 1: Add a Passenger‬

‭ s an admin, you can add new passengers to the system by entering the‬
A
‭following details:‬

‭The system will store this information in the database.‬

‭Output:‬

‭Option 2: View All Passengers‬

‭ electing the “View All Passengers” option will show the list of all registered‬
S
‭passengers:‬

‭41‬
‭4. Managing Bookings (User Section)‬

‭Option 1: Book a Flight‬

‭ s a user, you can book a flight by selecting a flight and providing the seat‬
A
‭number:‬

‭ he system will create the booking and assign the passenger to the selected‬
T
‭flight.‬

‭Output:‬

‭Option 2: View Your Bookings‬

‭ sers can check their bookings by viewing their passenger ID and associated‬
U
‭flight details.‬

‭5. Managing Crew (Admin Section)‬

‭Option 1: Add Crew Member‬

‭To manage crew, an admin can add a crew member to a flight:‬

‭42‬
‭This will add the crew member to the selected flight.‬

‭Output:‬

‭Option 2: View Crew Members‬

‭You can view all crew members assigned to different flights:‬

‭6. Additional Operations‬

‭Booking Cancellation (Optional)‬

‭Users can cancel a booking by selecting the booking ID:‬

‭This will remove the booking from the system.‬

‭Output:‬

‭Summary of Available Actions (For Admin and User)‬

‭43‬
‭●‬ ‭Admin Options‬‭:‬
‭1.‬ ‭Manage Flights‬‭: Add, View, Delete flights.‬
‭2.‬ ‭Manage Passengers‬‭: Add, View passengers.‬
‭3.‬ ‭Manage Crew‬‭: Add crew members to flights.‬
‭●‬ ‭User Options‬‭:‬
‭1.‬ ‭Book Flights‬‭: Select flight, choose seat, book.‬
‭2.‬ ‭View Bookings‬‭: Check bookings made.‬
‭3.‬ ‭Cancel Booking‬‭: Remove a booking if needed.‬

‭How to Use:‬
‭ .‬ ‭Run the script.‬
1
‭2.‬ ‭Log in or create a new account.‬
‭3.‬ ‭If you're an‬‭admin‬‭, you can manage flights, passengers,‬‭and crew.‬
‭4.‬ ‭If you're a‬‭user‬‭, you can book flights, view bookings,‬‭and cancel them.‬

‭44‬
‭45‬

You might also like