Python_ Advantages, Diversification, and Future-Proofing - Google Docs
Python_ Advantages, Diversification, and Future-Proofing - Google Docs
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 strengthsis 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 richstandard
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 inherentlycross-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-suitedfor 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 forvarious 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 growthin 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 indata 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 automatingrepetitive
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 traditionallyused 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.
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 academicsettings,
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 shownits
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 languageused 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 beeasy to learn
and use, with a syntax that is both intuitive and readable. Its
declarative nature means that users focus on specifyingwhatdata
they want, rather thanhowto retrieve it, makingSQL accessible to
non-programmers and business analysts as well.
3. Powerful Data Manipulation: SQL provides powerfulcapabilities 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 designedto
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 handlevast 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 crucialrole 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 datawarehousing,
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 adaptedto 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 traditionallynot
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 usedin 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.
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: WhileNoSQL
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 privacyand 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 artificialintelligence
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.
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:
10
integrating MySQL into their applications is a straightforward
process.
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.
SELECTqueries, this means fetching the rows returnedby
For
fetchall()to
the database. Python provides methods like
fetchone()to retrieve a singlerow.
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.
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:
SELECTquery, you can use methodslike
○ 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-exceptblock, which helps catch any exceptionsthat
might arise during the connection or query execution. This
ensures that your application doesn’t crash due to unexpected
errors.
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 DELETEstatement 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.
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 MySQLdatabases
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.
16
■ c rew: Stores information about the flight crew (e.g., pilot,
co-pilot, cabin crew) and links them to specific flights via
theflight_id .
■ users: Holds the credentials of users of the system.Each
user has a unique usernameand apasswordthat are
used for authentication.
User Management
Sign Up Functionality
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 theuserstable. If the credentials arevalid, the user is granted
access to the main menu; otherwise, an error message is shown, and the
user is prompted to try again.
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 destinationairports.
● 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 theflightstable.
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 flightstable.
Passenger Management
Add Passenger:
● U sers are prompted to enter passenger details such as name, age,
gender, and mobile number.
passengerstable.
● 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.
bookingstable.
● This information is stored in the
View Bookings:
bookingstable.
● The user can view all bookings from the
Crew Management
● 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 crewtable.
● T
he system displays all crew members and their roles, as stored in
crewtable.
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
passengerstable.
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 bookingstable.
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 theAirline Management System(AMS) effectively, both hardware
T
and software components are required. Below is a breakdown of the
hardwareandsoftwarerequirements needed to set upand 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 Serveror 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
○ If 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 theAirline
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.
○ MariaDBcan be an alternative to MySQL if needed.
4. Integrated Development Environment (IDE):
○ Visual Studio Code: A powerful and lightweight editorfor
writing Python code.
○ PyCharm: A feature-rich IDE specifically for Python
development.
○ AtomorSublime Text: Lightweight and fast text editorsfor
Python development.
5. Required Python Libraries/Packages:
○ mysql-connector-python: For connecting Python withMySQL
databases.
○ Tkinter(optional): If you plan to develop a graphicaluser
interface (GUI) version of the AMS.
○ pandas(optional): For advanced data manipulationand
reporting.
○ datetime: To handle date and time operations (forflight
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 managingyour
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 securefrom
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.
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-pythonfor
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
==================================
""")
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: ")
if 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.
This creates a new user and stores their credentials in the system.
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:
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:
If 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:
s an admin, you can add new passengers to the system by entering the
A
following details:
Output:
electing the “View All Passengers” option will show the list of all registered
S
passengers:
41
4. Managing Bookings (User Section)
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:
sers can check their bookings by viewing their passenger ID and associated
U
flight details.
42
This will add the crew member to the selected flight.
Output:
Output:
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 anadmin, you can manage flights, passengers,and crew.
4. If you're auser, you can book flights, view bookings,and cancel them.
44
45