0% found this document useful (0 votes)
2 views28 pages

PPS UNIT_1

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 28

PPS Unit-I(2024 Pattern) DIT,Pimpri

Dr. D. Y. PATIL INSTITUTE OF TECHNOLOGY, PIMPRI, PUNE-18


Department of First Year Engineering
Programming and Problem Solving
Unit- 1 Notes

Unit I: Problem Solving, Programming and Python Programming

Syllabus:
General Problem Solving Concepts- Problem solving in everyday life, types of
problems, problem solving with computers, difficulties with problem solving, problem
solving aspects, top down design, Problem Solving Strategies
Basics of Python Programming: Features of Python, History and Future of Python,
Programming Paradigm,
Features of Object Oriented Programming, Applications of Python Languages.

1.1 General Problem Solving Concepts

1.1.1 Problem Solving in Everyday Life:


Q.1. Define Problem. What are steps in problem solving?
Definition of problem
Problem is defined as a situation or issue or condition which needs to be solve
to achieve a specific goal.
Steps in problem solving
1. Identify the problem - You need to be clear about what exactly the problem
is. If the problem is not identified then it cannot be solved. example- when
you want to learn a language then first identify which language do you want to
learn
2. Understand the problem - Here problem should be defined properly so that
it helps in understanding the problem more. It helps to understand knowledge
base of the problem. It helps in finding a target for what you want to achieve.
3. Identify alternative ways to solve the problem - This step is very crucial
because until and unless we explore all options, finding a correct solution is
next to possible. This involves the process to create a list of solutions.

1
PPS Unit-I(2024 Pattern) DIT,Pimpri

4. Select the best way to solve the problem - Identify and evaluate pros and
cons of each possible solution and then select the best solution. Selecting
proper way from alternatives require a lot of study and need to study con-
sequences as well.
5. List instructions that enable you to solve the problem using
selected solution - Here we need to list out the steps which should
be followed so that anyone can solve the problem. This should be in
detail and precise at the same time.
6. Evaluate the solution - It mean to test the solution and check if the
result is satisfactory or not.
Example: I am always late for college
(i) Identification: getting late for college.
(ii) Understanding: (List out probable reasons of or getting late)
(Sleeping late, waking up late, Transportation, etc.)
(iii) List out alternative ways – (Solutions)
(a). Sleeping early at home.
(b). Waking up early.
(c). Waking alarm.
(d). Resolving travelling issue.
(iv) Select the best way – Sleeping early in night.
(v) List out the procedure
(a). Having dinner as early as possible.
(b). Avoid use of mobile phones in night.
(c). Completing homework as early as possible.
(d). Then going early to bed.
(vi) Evaluate the solution: Reached College on time.

1.1.2 Types of problems:

Q. 2. Explain types of problems in detail?


Ans:
Problem can be categorized into two types depending on how the solution is found out or
the approach which is followed to get that solution.
(i) Algorithmic solution
(a) These problems are solved by following some procedure or steps.
(b) For example: baking a cake. It can be done by following a series of instruction

2
PPS Unit-I(2024 Pattern) DIT,Pimpri

And we can expect results.


(c) Here following some predefined process needs to be done.
(d) Here solution is quite straight forward.
(ii) Heuristic solution
(a) These types of problems solved using knowledge based i.e. by collecting
information about the problem.
(b) For example: Expanding one’s business.
(c) In this type of approach there is no straight forward defined path which we can
follow to solve a problem.
(d) We need to build that path based on trial and error.
(e) In this approach experience and knowledge is very important.

1.1.3 Problem Solving with computers:

Q. 3. Write a note on Problem solving with computers.


Ans: Computer is a multi-purpose electronic machine which is used for storing,
organizing and processing the data.
Computer is not able to find the solution by itself; rather the computer is a machine
which follows the instruction given by programmer to solve any problem.
So all the efforts required to understand the problem and define procedure to solve that
problem are taken by programmer (a human being).

Problem Definition:
Before a program is written for solving a problem, it is important to define the problem
clearly.
Define problem: Problem is defined as a situation or issue or condition which
needs to solve to achieve the goal.
For most of the software projects, the system analyst approach system users to
collect user requirements and define the problem that the system aims to solve.
System analyst typically looks at following issues:

3
PPS Unit-I(2024 Pattern) DIT,Pimpri

 What input is required for achieving expected output?


 Expected output of the problem.
 Current method of solving the problem.
 Can the problem or part of the problem be more effectively solved by a
software solution?
 Computers are built to deal with algorithmic solutions, which are often
difficult or very time consuming for humans.
Solution:
 Solution means the instructions listed during problem solving – the instructions
that must be followed to produce the best results.
 The result may be: More efficient, faster, more understandable or reusable.
Results:
 The result is outcome or the completed computer assisted answer.
 May take any form: Printout, updated files, output to monitor speakers, etc.
Program:
o Program is the set of instructions that make up the solution after they have been
coded into a particular computer language.

1.1.4 Difficulties with problem solving:

Q.4. Explain the difficulties with Problem solving?


Ans:
 Some people may not have got training regarding how to solve problems.
 Some may not able to make a decision for fear it will not be the correct one.
 There may be inaccuracy in defining the problem correctly or may not generate
the sufficient list of alternatives.
 While selecting best alternative, they may skip better alternative due to urgency.
 The problem solving process is difficult. It takes practice as well as time to
perfect, but in the long run the process proves to be of great benefit.
 Illogical sequencing of instructions: In the process of problem solving on the
4
PPS Unit-I(2024 Pattern) DIT,Pimpri

computer, one of the most complicated jobs for the problem solver is writing the
instructions.
Example: Consider a task to find which number is the maximum from a set of
three numbers. Near about everyone is immediately able to tell which is the
largest but several of them are unable to explain the steps they followed to get
the result. Computer is nothing but a machine that will perform only task that
the user can explain.

1.1.5 Problem Solving Aspects:

Q.6. What is modularization? Explain different approaches to design an


algorithm.
Ans:
Modularization:
For a complex problem, its algorithm is often divided into smaller units called modules.
This process of dividing an algorithm into modules is called as modularization.

Top down design approach:


● A top-down design approach starts by dividing the complex algorithm into
one or more functions.
● These functions can further be decomposed into one or more sub-functions,
and this process of decomposition is iterated until the desired level of module
complexity is achieved.
● Top-down design method is a form of stepwise refinement where we begin
with the topmost module and incrementally add functions that it calls.
● Therefore, in a top-down approach, we start from an abstract design and then
at each step, this design is refined into more concrete levels until a level is
reached that requires no further refinement.

5
PPS Unit-I(2024 Pattern) DIT,Pimpri

Fig: Top Down Approach

Bottom up design approach:


● It is just reverse of top down approach.
● In bottom up design, we start with designing the most basic or concrete modules
and then proceed towards designing higher level modules.
● The higher level modules are implemented by using the operations performed by
lower level modules.
● Thus, in this approach sub-modules are grouped together to form higher level
module.
● All the higher level modules are clubbed together to form even higher level
modules.
● This process is repeated until the design of the complete algorithm is obtained.

Difference between Top down and Bottom up approach:

Top-Down Approach Bottom-Up Approach

Divides a problem into smaller units and then Starts from solving small modules and
solve it. adding them up together.

This approach contains redundant information. Redundancy can easily be eliminated.

6
PPS Unit-I(2024 Pattern) DIT,Pimpri

Communication among steps is


A well-established communication is not required. mandatory.

Works on the concept of data-hiding


The individual modules are thoroughly analysed. and encapsulation.

Structured programming languages such as C use OOP languages like C++ and Java,
top-down approach. etc. uses bottom-up mechanism.

The modules must be related for


Relation among modules is not always required. better communication and work flow.

Primarily used in code implementation, test case


generation, debugging and module documentation. Finds use primarily in testing.

1.1.6 Problem Solving Strategies:

Q.5. Explain the problem solving Strategies?


Ans.
Computer is a very powerful and versatile machine and can do any task given to it
provided that the programmer has already fed correct instructions to direct what, how and
when the steps have to be done to solve a particular problem. For this he should work to
develop a step by step solution to problem. These steps can be given as:
● Clearly define the problem in very simple and precise language.
● Analyze the problem to find out different ways to solve problem and decide the
best possible solution.
● Define the selected solution in a detailed step by step manner.
● Write the steps in a particular programming language so that it can be executed
by the computer.
The entire software development process is divided into a number of phases where each
phase performs a well defined task. Moreover, the output of one phase provides the input
for subsequent phase. The phases in the software development life cycle (SDLC) process
are summarized as follows:
7
PPS Unit-I(2024 Pattern) DIT,Pimpri

Fig: Software Development Life cycle (SDLC)

● Requirement Analysis: In this phase, the user’s expectations are gathered to know
why the software has to be built. The gathered requirements are analyzed to
decide scope of software. The last activity in this phase includes documenting
every identified requirement of the users in order to avoid any doubts regarding
functionality of software. The functionality, capability, performance and
availability of hardware and software components are all analyzed in this phase.

● Design: The requirements documented in previous phase act as an input to the


design phase. In the design phase, core structure of the software is broken down
into modules. The solution of the program is specified for each module in the
form of algorithms or flowcharts.

● Implementation: In this phase, the designed algorithms are converted into


program code using any of the high level languages. The particular choice of
language will depend on the type of program, such as whether it is system or
application program. This phase is also called as construction phase as the code of
8
PPS Unit-I(2024 Pattern) DIT,Pimpri

the software is generated in this phase. While constructing the code, the
development team checks whether the software is compatible with available
hardware that are mentioned in requirement specification document.

● Testing: In this phase all modules are tested together to ensure that the overall
system works well as a whole product. In this phase the software is tested using a
large number of varied inputs, also known as test data, to ensure the software is
working as expected by user’s requirements.

● Software development, training and support: After the code is tested and the
software or the program has been approved by the users, it is installed or
deployed in the production environment. In this phase it becomes very crucial to
have training classes for users of software.

● Maintenance: Maintenance and enhancement are ongoing activities that are done
to cope with newly discovered problems or new requirements. Such activities
may take a long time to complete as the requirement may call for the addition of
new code that does not fit original design or an extra piece of code, required to fix
an unforeseen problem.

1.2 Basics of Python Programming

1.2.1 Features of Python


Q.15. Explain various features of python.
Ans.
1. Simple: Python is simple and small language. Reading a program written in
python feels like reading English.
2. Easy to Learn: Python programming is clearly defined and easily readable.
3. Versatile: Python supports wide variety range of applications ranging from text
processing to Web applications
4. Free and Open Source: Python software is freely available on internet

9
PPS Unit-I(2024 Pattern) DIT,Pimpri

5. High Level Language: Programmers don’t have to worry about low level details
like managing memory used by program etc.
6. Interactive: Programs in python works in interactive mode
7. Portable (Platform Independent): Python is portable language. Program can
work similarly on different platform like window, Linux, Macintosh, Solaris etc.
8. Object Oriented: Python supports Object oriented style of programming like
C++, Java languages. It support features like C class, Objects, Inheritance etc.
9. Interpreted: Python is processed at run time by the interpreter. So no need to
compile program before executing it.
10. Scalability: Python support modular programming, so programmer can add
module at any stage of the program
11. Secure: Python programming environment is secure from tempering

1.2.2 History and Future of Python


● Python is a general purpose interpreted interactive object oriented and high level
programming language.
● It was first introduced in 1991 by Guido van Rossum, a Dutch computer
programmer.
● The language places strong emphasis on code reliability and simplicity so that the
programmers can develop applications rapidly
● Python is multi-paradigm programming language, which allows user to code in
several different programming styles.
● Python supports cross platform development and is available through open
source. Python is widely used for scripting in Game menu applications effectively

History of Python:
● Python is created by Guido Van Rossum in the 1980s.
● Rossum published the first version of Python code (0.9.0) in February 1991 at the
CWI (Centrum Wiskunde & Informatics) in the Netherlands , Amsterdam.
● Python is derived from ABC programming language, which is a general-purpose
programming language that had been developed at the CWI.
10
PPS Unit-I(2024 Pattern) DIT,Pimpri

● Rossum chose the name "Python", since he was a big fan of Monty Python's
Flying Circus.
● Python is now maintained by a core development team at the institute, although
Rossum still holds a vital role in directing its progress.

Future of Python:

● Python’s user base is vast and growing – it’s not going away any time soon.
● Utilized by the likes of Nokia, Google, and even NASA for it’s easy syntax, it looks
to have a bright future ahead of it supported by a huge community of OS developers.
● Its support of multiple programming paradigms, including object-oriented Python
programming, functional Python programming, and parallel programming models
makes it a highly adaptive choice – and its uptake keeps growing.

1.2.3 Programming Paradigm

Definition: A programming paradigm is a fundamental approach or style of


programming that provides principles and techniques for structuring and solving
problems using code.
Purpose: Paradigms guide how programs are designed, organized, and executed,
influencing problem-solving strategies and code structure.

Q1. Write a note on:


1. Monolithic Programming
2. Procedural Programming
3. Structured Programming
4. Object Oriented Programming
Ans.
(i) Monolithic Programming Paradigm:
 Programs written using monolithic programming languages such as assembly
language consist of global data and sequential code.

11
PPS Unit-I(2024 Pattern) DIT,Pimpri

 The global data can be accessed and modified from any part of the program.
 A sequential code is one in which all instructions are executed in the specified
sequence.
 In order to change the sequence of instructions, jump statements or ‘goto’
statements are used.
 Structure of a monolithic program:

Advantages:
 Monolithic programming language is used only for very small and simple
applications.
 Monolithic programming language is used only for applications where
reusability is not a major concern.

Disadvantages:
 Monolithic programs have just one program module as monolithic
programming languages do not support the concept of subroutines.
 As it is containing just one program module, all the actions required
completing particular task are embedded within same application itself.
This makes the size of program large.
 It is difficult to debug and maintain monolithic programs.

12
PPS Unit-I(2024 Pattern) DIT,Pimpri

(ii) Procedural Programming Paradigm:


 In procedural programming language, a program is divided into n number
of subroutines that access global data.
 To avoid repetition of code, each subroutine performs a well-defined task.
 A subroutine that needs the service provided by another subroutine can
call that subroutine.
 Therefore, with ‘jump’,’goto’, and ‘call’ instructions, the sequence of
execution of instructions can be altered.
 For example, FORTRAN and COBOL are two popular procedural
programming languages.
 Structure of a procedural program:

 Advantages:
 This paradigm is used to write just correct programs.
 Programs using this paradigm are easier to write as compared to
monolithic programming.
 Disadvantages:
 Writing programs is complex.
 No concept of reusability.
 It requires more time and effort to write programs.
 Programs are difficult to maintain.
 Global data is shared and therefore may get altered (mistakenly).

(iii) Structured Programming Paradigm:


 Structured programming is also known as modular programming.
13
PPS Unit-I(2024 Pattern) DIT,Pimpri

 By using structured programming paradigm, programs are designed to


implement a logical structure on the program.
 Due to this, program becomes more efficient and easier to understand.
 Structured programming is used in large programs that require a large
development team to develop different parts of the same program.
 Structured programming employs a top-down approach in which the
overall program structure is broken down into separate modules.
 Due to this top-down approach, the code is loaded into memory more
efficiently and also can be reused in other programs.
 Modules are coded separately and once a module is written and tested
individually, it is then integrated with other modules to form the overall
program structure.
 Structured programming is based on modularization. Modularization
groups related statements together into modules.
 Modularization makes programming easier to write, debug and
understand.

 Advantages:
 Structured programming is used to write correct programs that are
easy to understand and change.

14
PPS Unit-I(2024 Pattern) DIT,Pimpri

 Structured programming allows users to look at the big picture first


and then focus on details later by using modules.
 With modules, many programmers can work on a single, large
program, with each working on a different module.
 A structured program takes less time to be written than other
programs. Also modules or procedures written for one program can be
reused in other programs as well.
 Each module performs a specific task.
 Each module has its own local data.
 A structured program is easy to change as well as understand because
every procedure has meaningful names and has clear documentation to
identify the task performed by it.
 A structured program is easy to debug because each procedure is
specialized to perform just one task and every procedure can be
checked individually for the presence of any error.
 Structured programming gives more emphasis on code and the least
importance is given to the data.

 Disadvantages:
 Structured programming is not data-centered.
 Global data is shared and may get modified.
 In structured programming, main focus is on functions.

(iv) Object-oriented Programming (OOP) Paradigm:


 Object-oriented programming paradigm treats data as a critical element in the
program development.
 In this paradigm, all relevant data and tasks are grouped together in entities
known as objects.
 Object-oriented programming is task based as it considers operations.

15
PPS Unit-I(2024 Pattern) DIT,Pimpri

 Object-oriented programming is data-based as these operations are grouped with


relevant data in objects.
 Every object contains some data and the operations, methods, or functions that
operate on that data.
 Programs that need the object will access the object’s methods through a specific
interface. The interface specifies how to send a message to the object, that is, a
request for a certain operation to be performed.

 Advantages:
 OOP is used for simulating real world problems on computers because the
real world is made up of objects.
 Programs written using OOP are data centered.
 Programs are divided in terms of objects and not procedures.
 Functions that operate on data are tied together with the data.
 Data is hidden and not accessible by external functions.
 New data and functions can be easily added as and when required.
 It follows a bottom-up approach for problem solving.
 Disadvantages:
o It requires more data protection.

16
PPS Unit-I(2024 Pattern) DIT,Pimpri

o Inability to work with existing systems.


o Larger program size.
o Not suitable for all types of problems-for smaller problems it is in general
not suitable.

Q2.Differentiate between Procedural and Object oriented programming.

Index Object-oriented Programming Procedural Programming

1. Object-oriented programming is the Procedural programming uses a list of


problem-solving approach and used instructions to do computation step by
where computation is done by using step.
objects.

2. It makes the development and In procedural programming, It is not


maintenance easier. easy to maintain the codes when the
project becomes lengthy.

3. It simulates the real world entity. So It doesn't simulate the real world. It
real-world problems can be easily works on step by step instructions
solved through oops. divided into small parts called
functions.

4. It provides data hiding. So it is more Procedural language doesn't provide


secure than procedural languages. You any proper way for data binding, so it
cannot access private data from is less secure.
anywhere.

5. Example of object-oriented Example of procedural languages are:


programming languages is C++, Java, C, Fortran, Pascal, VB etc.
.Net, Python, C#, etc.

17
PPS Unit-I(2024 Pattern) DIT,Pimpri

1.2.4 Features of Object Oriented Programming

Q3. Explain features of OOP.


Or
Q3. Write a note on: 1.___ 2.____ 3.____

1. Classes
 A class is user-defined data type used to describe something in the world,
such as occurrences, things, external entities, and so on.
 A class describes template or blueprint that describes the structure and
behavior of a set of similar objects.
 Once we have definition for a class, a specific instance of that class can be
easily created.
 For eg. Consider a class student. A student has attributes such a roll_no,
name, course and aggregate. The operations that can be performed on its
data may include ‘getdata’, ‘setdata’,’editdata’ and so on.
 A class is collection of objects.

2. Objects
 Object is basic unit of object-oriented programming.
 Object is basic run-time entity in an object-oriented system.
 Anything having its own properties can be considered as an object.
 For example flower is an object having properties such as name, fragrance,
etc.
 An object is a collection of data members and associated member function
also known as methods shown in figure1 below:

18
PPS Unit-I(2024 Pattern) DIT,Pimpri

Object Name
Attribute 1
Attribute 2

.........
Attribute N
Function 1
Function 2

.........
Function N

Figure1: Representation of an Object

3. Methods and Message passing


Methods
 A method is a function associated with class.
 It defines the operations that the object can execute when it receive a
message.
 In object oriented language, only methods of the class can access and
manipulate the data stored in an instance of the class (or object).
 Figure2 shows how a class is declared using its data members and member
functions.

19
PPS Unit-I(2024 Pattern) DIT,Pimpri

Figure2: Objects sending a message


Message Passing
 Two objects communicate with each other though messages.
 An object asks another object to involve one of its methods by sending it a
message.
 In figure2 sender object is sending message to the receiver object to get
details of a student. i.e. the sender is passing some specific information to the
receiver so that the receiver can send the correct and precise information to
the sender. The data that is transferred with the message is called parameters.
Here, roll_no 1 is the parameter.
 The messages that are sent to other objects consist of three aspects-the
receiver object, the name of the method that the receiver should invoke, and
the parameters that must be used with the method.

4. Inheritance (‘is-a’ relation)


 Inheritance is a concept of OOP in which a new class is created from an
existing class.
 The new class, often known as a subclass, contains the attributes and methods
of the parent class. (the exiting class from which the new class is created).
 The new class, known as a subclass or derived class, inherits the attributes
and behavior of pre-existing class, which is referred to as superclass or
parent class. (refer figure3.)

20
PPS Unit-I(2024 Pattern) DIT,Pimpri

Figure3: Child, derived or subclass

 The inheritance relationship of a subclasses and superclasses generates a


hierarchy. Therefore inheritance relation is also called as ‘is-a’ relation.
 A subclass not only has all the states and behavior associated with superclass
but has other specialized features (additional data or methods) as well.
 The main advantage is ability to reuse the code.
 For example, we have a class student with following members:
Properties: rollno, name, course, marks
Methods: getdata, setdata

Student

Undergraduate Postgraduate
Student Student

Figure4. Example of Inheritance


21
PPS Unit-I(2024 Pattern) DIT,Pimpri

 We can inherit two classes from the class student- undergraduate students and
postgraduate students (refer figure4). These two classes will have all the
properties of class students and in addition to that it will have even more
specialized members.
 When a derived class receives a message to execute a method, it finds the
method in its own class. If it finds the method, then it simply executes it. If
the method is not present, it searches for that method in its superclass. If the
method is found, it is executed; otherwise, an error message is reported.

5. Polymorphism
 Polymorphism refers to having several different forms.
 While inheritance is related to classes and their hierarchy, polymorphism on
other hand, is related to methods.
 Polymorphism is a concept that enables the programmers to assign a different
meaning or usage to a method in different context.
 Polymorphism exist when a number of subclasses is defined which have
methods of same name.
 Polymorphism can also be applied to operators.

6. Containership (composition or has-a’ relationship )


 Containership is ability of a class to contain object(s) of one or more classes
a member data.
 For example, class Person can have an object of class Student as its data
member. This would allow the object of class Person to call the public
functions of class Student. Here class Person becomes the container, whereas
class Student becomes the contained class.
 Containership is also called composition because as in given example, class
Person is composed of class Student.
 In OOP, containership represents a ‘has-a’ relationship.

22
PPS Unit-I(2024 Pattern) DIT,Pimpri

7. Reusability
 Reusability means developing codes that can be reused either in the same
program or in the different programs.
 Reusability is attained through inheritance, containership and
polymorphism.

8. Delegation
 To provide maximum flexibility to programmers and to allow them to
generate a reusable code, object oriented languages also support delegation.
 In composition, an object can be composed of other objects and thus, the
object exhibits a ‘has-a’ relationship.
 In delegation, more than one object is involved in handling a request. The
object that receives the request for a service, delegates it to another object
called its delegate.
 Delegation means that one object is dependent on another object to provide
functionalities.
 The property of delegation emphasizes on the ideology than a complex object
is made of several simpler objects.
 For example, our body is made up of brain, heart, hands, eyes, ears, etc. The
functioning of the whole body as a system rests on the correct functioning of
the parts it is composed of.
 Delegation is different from inheritance in the way that two classes that
participates in inheritance share ‘is-a’ relationship; however, in delegation,
they have a ‘has-a’ relationship.

9. Data Abstraction
 Data Abstraction refers to the process by which data and functions are
defined in such a way that only essential details are revealed and the
implementation details are hidden.

23
PPS Unit-I(2024 Pattern) DIT,Pimpri

 The main focus of data abstraction is to separate the interface and


implementation of a program.
 For example, as user of television sets, we can switch it on or off, change the
channel, set the volume and add external devices such as speakers and CD or
DVD players without knowing the details how its functionality has been
implemented. Therefore the implementation is completely hidden from
external world.

10. Encapsulation (Data hiding)


 Data encapsulation, also called data hiding, is the technique of packing data
and functions into a single component (class) to hide implementation details
of a class from users.
 Users are allowed to execute only a restricted set of operations (class
methods) on the data members of the class.
 Therefore encapsulation organizes the data and methods into a structure that
prevents data access by any function (or method) that is not specified in the
class. This ensures the integrity of the data contained in the object.
 Encapsulation defines three access levels for data variables and member
functions of the class. These access levels specify the access rights, explained
as follows:
o Any data of function with access level as public can be accessed by
any function belonging to any class. This is lowest level of data
protection.
o Any data of function with access level as protected can be accessed
only by that class or by any class that is inherited from it.
o Any data of function with access level as private can be accessed
only by the class in which it is declared. This is highest level of data
protection.

24
PPS Unit-I(2024 Pattern) DIT,Pimpri

1.2.5 Applications of Python Language

1. Web Development:
Python is widely used to build robust and scalable web applications using
frameworks like Django, Flask, and FastAPI. These frameworks simplify
development by providing tools for database interaction, routing, and security.
Python’s versatility allows developers to create anything from personal blogs to
enterprise-level websites.
2. Data Science and Analytics:
Python is a go-to language for data scientists due to libraries like Pandas, NumPy,
and Matplotlib. It allows users to clean, analyze, and visualize data efficiently.
Combined with machine learning libraries like scikit-learn, Python enables
predictive analysis and insights generation.
3. Artificial Intelligence and Machine Learning:
Python plays a crucial role in AI and ML applications with frameworks like
TensorFlow and PyTorch. It is used for tasks like natural language processing,
image recognition, and building recommendation systems. Its simplicity and vast
community support make it ideal for AI projects.
4. Scientific Computing:
Python supports high-performance scientific computing with libraries like SciPy
and SymPy. Researchers use it for complex simulations, solving mathematical
problems, and running statistical models. Its integration with Jupyter Notebooks
enhances collaborative research.
5. Automation and Scripting:
Python is frequently used to automate repetitive tasks such as file handling, data
entry, and testing. Libraries like Selenium and PyAutoGUI allow for automated
web interactions and GUI control. This makes it invaluable for increasing
productivity in various domains.
6. Game Development:
Python is used in the gaming industry for prototyping and developing simple 2D
and 3D games. Libraries like Pygame and Panda3D provide tools for game
mechanics, animations, and graphics. Python’s readability helps game developers
quickly iterate and test ideas.
7. IoT and Robotics:
Python is a preferred language for IoT and robotics applications, especially with
platforms like Raspberry Pi and Arduino. It enables developers to interact with
sensors, actuators, and APIs. Python simplifies the control of hardware devices in
real-time projects.
8. Networking and Cybersecurity:
Python is popular for developing tools and scripts in network programming and
cybersecurity. Libraries like Scapy and Paramiko assist in packet sniffing, SSH
connections, and testing network vulnerabilities. It is also used to automate
security audits and penetration testing.
9. Desktop Application Development:
Python enables the development of interactive desktop applications using
frameworks like Tkinter, PyQt, and Kivy. These tools provide support for
25
PPS Unit-I(2024 Pattern) DIT,Pimpri

designing user interfaces, handling events, and managing cross-platform


compatibility. It is ideal for small to medium-scale application projects.
10. Education and Academics:
Python’s simple syntax and readability make it an excellent language for teaching
programming. It is widely used in academic settings to introduce computational
thinking, algorithms, and data structures. Its widespread adoption in education
ensures a strong foundation for learners.

26
PPS Unit-I(2024 Pattern) DIT,Pimpri

A. Writing and Executing Python Programs


● Open IDLE.
● Go to File > New.
● Write Python code in the file.
● Then save the file with .py extension. For example, hello.py, example.py etc.
You can give any name to the file. However, the file name should end with .py
● Run the program.

B. Input and Output operation


input() and print() functions are widely used for standard input and output operations
respectively.
1.input()
To allow flexibility we might want to take the input from the user. In Python, we have
the input() function to allow this.
Syntax:
input (expression)
2.print()
We use the print() function to output data to the standard output device (screen).
print() evaluates the expression before printing it on the monitor. Print statement outputs
an entire (complete) line and then goes to next line for subsequent output (s). To print
more than one item on a single line, comma (,) may be used.
Syntax:
print (expression/constant/variable)
Example:

x = input("Enter any value: ")


# printing value
print("Entered value is: ", x)

27
PPS Unit-I(2024 Pattern) DIT,Pimpri

C. Comments
· The comments are ignored by the interpreter and are used to add additional
information about the program or its statements.
· They can be written anywhere in the program.
· Two way comments can be given in Pyhton
1. One line comments using (#)
2. Multi line comments using (‘’’ ‘’’)
· Comments in Python begins with ’ #’ character.
· A comment may appear at the beginning of a line or can be placed after
whitespace or code, but not within a string literal.
Example:1
#This is first Python Program
print(“Hello World”) # prints Hello World
Example: 2
''' program is written for addition
Of two numberd '''
x=10
y=20;
Print(x+y)

D. Indentation
● White space at the beginning of the line is called indentation.
● These white spaces or the indentation are very important in python.
● In python program, the leading white space and tabs at the beginning of the
logical line determines the indentation level of logical line.
● All statements inside block should be at same indentation level.
● Python checks the indentation level very strictly and gives an error if
indentation is not correct.
Use of indentation:
● In most of the programming languages, indentation has no effect on program
logic. It is used to align statements to make the code readable.
● However, in python indentation is used to associate and group statements.
Example:
Program to find number is even or odd
num = int(input("Enter a number: "))
if (num % 2) == 0:
print("Number is even")
else:
print("Number is Odd")

28

You might also like