BACSE101 - Problem Solving using Python
Dr. Dega Nagaraju, [Link]. (IE), [Link]. (CSE-AI & ML), Ph.D.
School of Computer Science and Engineering
Vellore Institute of Technology, Vellore-632014
29/10/2025 [Link] Nagaraju, SCOPE, VIT 1
Stages of Industrial Revolution
29/10/2025 [Link] Nagaraju, SCOPE, VIT 2
Stages of Industrial Revolution
29/10/2025 [Link] Nagaraju, SCOPE, VIT 3
Introduction
• Purpose
Every engineering student should learn how to program for problem solving in the
domain and can optimize the tech-task easily and efficiently with computer
programming knowledge
• Objectives
1) To provide exposure to basic problem-solving techniques using computers.
2) To inculcate the art of logical thinking abilities and propose novel solutions for real
world problems through programming language constructs.
• Outcomes
1) Classify various algorithmic approaches, categorize the appropriate data
representation, and demonstrate various control constructs.
2) Choose appropriate programming paradigms.
3) Interpret and handle data using files to propose solution through reusable modules.
4) Idealize the importance of modules and packages.
29/10/2025 [Link] Nagaraju, SCOPE, VIT 4
29/10/2025 [Link] Nagaraju, SCOPE, VIT 5
Programming paradigm (Contd…)
Paradigm can also be termed as method to solve some problem or do
some task.
Programming paradigm is an approach to solve problem using some
programming language
It is a method to solve a problem using tools and techniques that are
available to us following some approach.
There are lots for programming language that are known but all of them
need to follow some strategy when they are implemented and this
methodology/strategy is paradigms.
29/10/2025 [Link] Nagaraju, SCOPE, VIT 6
Programming paradigm (Contd…)
Imperative programming paradigm:
It is one of the oldest programming paradigm.
It features close relation to machine architecture.
It is based on Von Neumann architecture.
It works by changing the program state through assignment statements.
It performs step by step task by changing state.
The main focus is on how to achieve the goal.
The paradigm consist of several statements and after execution of all, the
result is stored.
Advantages: Disadvantage:
Very simple to implement Complex problem cannot be solved
Less efficient and less productive
It contains loops, variables etc.
29/10/2025 [Link]
Parallel programming
Nagaraju, SCOPE, VIT is not possible 7
Programming paradigm (Contd…)
Examples of Imperative programming paradigm:
C : developed by Dennis Ritchie and Ken Thompson
Fortran : developed by John Backus for IBM
Basic : developed by John G Kemeny and Thomas E Kurtz
29/10/2025 [Link] Nagaraju, SCOPE, VIT 8
Programming paradigm (Contd…)
Procedural programming paradigm
This paradigm emphasizes on procedure in terms of under lying machine
model.
It has the ability to reuse the code.
Examples:
29/10/2025 [Link] Nagaraju, SCOPE, VIT 9
Programming paradigm (Contd…)
Object oriented programming
The program is written as a collection of classes and object which are
meant for communication.
The smallest and basic entity is object and all kind of computation is
performed on the objects only.
More emphasis is on data rather procedure.
It can handle almost all kind of real life problems which are today in
scenario.
Advantages:
Data security
Inheritance
Code reusability
Flexible and abstraction is also present
29/10/2025 [Link] Nagaraju, SCOPE, VIT 10
Programming paradigm (Contd…)
Encapsulation - process of bundling attributes and methods within a single unit
Polymorphism - allows entities like functions, methods or operators to behave differently based on
the type of data
Examples of Object Oriented programming paradigm:
Abstraction - focuses on hiding the complex implementation details of an application and exposing only
the essential functionalities to the user
29/10/2025 [Link] Nagaraju, SCOPE, VIT 11
Programming paradigm (Contd…)
Parallel processing approach:
Parallel processing is the processing of program instructions by dividing
them among multiple processors.
A parallel processing system posses many numbers of processor with the
objective of running a program in less time by dividing them.
This approach seems to be like divide and conquer.
Examples:
NESL (National E-Governance Services Limited) - one of the oldest one and
C/C++ also supports because of some library function.
29/10/2025 [Link] Nagaraju, SCOPE, VIT 12
Programming paradigm (Contd…)
Declarative programming paradigm:
It is divided as Logic, Functional, Database.
In computer science the declarative programming is a style of building
programs that expresses logic of computation without talking about its
control flow.
It often considers programs as theories of some logic.
The focus is on what needs to be done rather how it should be done
basically emphasize on what code is actually doing.
It just declares the result we want rather how it has be produced.
29/10/2025 [Link] Nagaraju, SCOPE, VIT 13
Programming paradigm (Contd…)
Logic programming paradigms:
It can be termed as abstract model of computation.
It would solve logical problems like puzzles, series etc.
In logic programming we have a knowledge base which we know before
and along with the question and knowledge base which is given to machine,
it produces result.
In logical programming the main emphasize is on knowledge base and the
problem.
The execution of the program is very much like proof of mathematical
statement, e.g., Prolog
29/10/2025 [Link] Nagaraju, SCOPE, VIT 14
Programming paradigm (Contd…)
Functional programming paradigms:
The functional programming paradigms has its roots in mathematics and
it is language independent.
The key principle of this paradigms is the execution of series of
mathematical functions.
Some of the languages like perl, javascript mostly uses this paradigm.
Examples:
29/10/2025 [Link] Nagaraju, SCOPE, VIT 15
Programming paradigm (Contd…)
Database/Data driven programming approach
This programming methodology is based on data and its movement.
Program statements are defined by data rather than hard-coding a series of
steps.
A database program is the heart of a business information system and
provides file creation, data entry, update, query and reporting functions.
Several programming languages are developed for database application.
Example SQL.
It is applied to streams of structured data, for filtering, transforming,
aggregating (such as computing statistics), or calling other programs.
29/10/2025 [Link] Nagaraju, SCOPE, VIT 16
Programming paradigm (Contd…)
Example for Database/Data driven programming approach
29/10/2025 [Link] Nagaraju, SCOPE, VIT 17
Course Content
Introduction to Problem
Solving
Python Programming
Control Structures
Collections
Computer
Programming:
Strings and Regular
Python
Functions and Files Expressions
Modules and Packages
References:
1. Eric Matthes, Python Crash Course: A Hands-On, Programming, 2nd Edition, No starch Press, 2019.
2. Martic C Brown, Python: The Complete Reference, 4th Edition, McGraw Hill Publishers, 2018.
3. John V. Guttag, Introduction to computation and programming using python: with applications to understanding data, 2nd
Edition, MIT Press, 2016.
29/10/2025 [Link] Nagaraju, SCOPE, VIT 18
Course Details
• Laboratory Based Component
• Course Credits
29/10/2025 [Link] Nagaraju, SCOPE, VIT 19
Rubrics Assessment (Evaluation)
*schedule of FAT as per the academic calendar from Dean, Academic
29/10/2025 [Link] Nagaraju, SCOPE, VIT 20
What is Python?
Python is a very popular general-purpose
interpreted, interactive, object-oriented,
and high-level programming language.
Python
dynamically-typed
is and garbage-
collected programming language.
It was created by Guido van Rossum during Encapsulation - process of bundling attributes and methods within a
single unit
1985 - 1990. Polymorphism - allows entities like functions, methods or operators to
behave differently based on the type of data
Abstraction - focuses on hiding the complex implementation details of
Like Perl, Python source code is also an application and exposing only the essential functionalities to the
user
available under the GNU General Public
GNU is an abbreviation of GNU's Not UNIX.
License (GPL). It is a computer operating system the same as UNIX,
but different from UNIX, it is free software that carries
no UNIX code.
Guh-noo is the pronunciation of GNU.
29/10/2025 [Link] Nagaraju, SCOPE, VIT 21
Scope for Python in Computer Science Domain
29/10/2025 [Link] Nagaraju, SCOPE, VIT 22
Software Tools
(Recommended)
Flowchart:
yEd Graphics Editor
• Online Version: [Link]
• PC Version: [Link]
[Link]
Python Programming:
• [Link]
Anaconda – Spyder
• PC Version: [Link]
29/10/2025 [Link] Nagaraju, SCOPE, VIT 23 23
Characteristics of Python:
Python is Interpreted − Python is processed at runtime by the interpreter.
You do not need to compile your program before executing it. This is similar
to PERL (Practical Extraction and Reporting Language) and PHP (Hypertext
Preprocessor).
Python is Interactive − You can actually sit at a Python prompt and interact
with the interpreter directly to write your programs.
Python is Object-Oriented − Python supports Object - Oriented style or
technique of programming that encapsulates code within objects.
Python is a Beginner's Language − Python is a great language for the
beginner-level programmers and supports the development of a wide range of
applications
29/10/2025
from simple text processing to WWW browsers to games.
[Link] Nagaraju, SCOPE, VIT 24
Execution process of C file:
29/10/2025 [Link] Nagaraju, SCOPE, VIT 25
Characteristics of Python:
Easy-to-learn − Python has few keywords, simple structure, and a clearly
defined syntax. This allows the student to pick up the language quickly.
Easy-to-read − Python code is more clearly defined and visible to the eyes.
Easy-to-maintain − Python's source code is fairly easy-to- maintain.
A broad standard library − Python's bulk of the library is very portable
and cross-platform compatible on UNIX, Windows, and Macintosh.
Interactive Mode − Python has support for an interactive mode which
allows interactive testing and debugging of snippets of code.
29/10/2025 [Link] Nagaraju, SCOPE, VIT 26
Characteristics of Python:
Portable − Python can run on a wide variety of hardware platforms and has the
same interface on all platforms.
Extendable − You can add low-level modules to the Python interpreter. These
modules enable programmers to add to or customize their tools to be more
efficient.
Databases − Python provides interfaces to all major commercial databases.
GUI Programming − Python supports GUI applications that can be created
and ported to many system calls, libraries andwindows systems, such as
Windows MFC, Macintosh, and the X Window system of Unix.
Scalable − Python provides a better structure and support for large programs
than shell scripting.
29/10/2025 [Link] Nagaraju, SCOPE, VIT 27
Way to Run Python:
IDLE (Integrated Development and Learning Environment)
Sublime Text 3
Atom
Thonny
PyCharm
Visual Studio Code
Vim
Spyder
29/10/2025 [Link] Nagaraju, SCOPE, VIT 28
Introduction to Problem Solving
Have you ever observed this scenario?
What are the problems in the scenario?
29/10/2025 [Link] Nagaraju, SCOPE, VIT 29
Introduction to Problem Solving
• Problem is a set of questions on a scenario which consists of description of
reality and set of constraints about the scenario and that requires logical
thought and /or mathematics to solve.
• All Problems do not have a straightforward solutions.
• Some problems, such as
• balancing a checkbook or
• baking a cake,
-can be solved with a series of actions.
-These solutions are called algorithmic solutions.
• There may be more than one solution for a problem
• Identify all possible ways to solve a problem and choose one among them
29/10/2025 [Link] Nagaraju, SCOPE, VIT 30
Introduction to Problem Solving
• The solutions of other problems, such as
• how to buy the best stock or
• whether to expand the company
are not so straightforward
• These solutions require reasoning, built in knowledge and experience, and a
process of trial and error.
• Solutions that cannot be reached through a direct set of steps are called
heuristic solution.
29/10/2025 [Link] Nagaraju, SCOPE, VIT 31
Introduction to Problem Solving
• Computers are built to solve problems with algorithmic solutions, which are
often difficult or very time consuming when input is large.
• Solving a complicated calculus problem or alphabetizing 10,000 names is
an easy task for the computer.
• So the basis for solving any problem through computers is by developing an
algorithm.
29/10/2025 [Link] Nagaraju, SCOPE, VIT 32
Introduction to Problem Solving
• Field of computers that deals with heuristic types of problems is called
Artificial Intelligence (AI)
• Artificial intelligence enables a computer to do things like human by
building its own knowledge bank
• As a result, the computer’s problem-solving abilities are similar to those of a
human being.
• Artificial intelligence is an expanding computer field, especially with the
increased use of Robotics.
Computational Problems:
• Computation is the process of evolution from one state to another in
accordance with some rules.
29/10/2025 [Link] Nagaraju, SCOPE, VIT 33
Introduction to Problem Solving
• Where the answer for every instance is either yes or No
Decision • Deciding whether the given number is prime
Problems
• Searching an element from a given set of elements or arranging them in an order
Searching • Finding product name for given product ID and arranging products in alphabetical order
and Sorting of names
Problems
• Counting number of occurrences of a type of element in a set of elements
Counting • Counting how many different type of items are available in the store
Problem
• Finding the best solution out of several feasible solutions
Optimization • Finding best combination of products for promotional campaign
Problem
29/10/2025 [Link] Nagaraju, SCOPE, VIT 34
Introduction to Problem Solving - steps
Defining / Understanding a Problem
Identifying Input / Output of the problem
Analyse alternate ways to solve the problem
Flow Chart/Pseudo Code
Debugging to fix bug if any
29/10/2025 Testing
[Link] Nagaraju, SCOPE, VIT 35
Introduction to Problem Solving- Logic (Basis for solving any
problem)
• Definition : A method of human thought that involves thinking in a linear,
step by step manner about how a problem can be solved
• Logic is a language for reasoning.
It is a collection of rules we use when doing reasoning.
• Example: John's mum has four children.
• The first child is called April.
• The second May.
• The third June.
• What is the name of the fourth child?
29/10/2025 [Link] Nagaraju, SCOPE, VIT 36
Problem Solving by Computer
• Solving problem by computer undergo two phases:
• Phase 1:
• Organizing the problem or pre-programming phase
(Problem analysis diagram, flow-chart, algorithm)
• Phase 2:
• Programming phase (coding the program)
29/10/2025 [Link] Nagaraju, SCOPE, VIT 37
Problem Solving by Computer
Organizing the problem or pre-programming phase – tools
Analyzing the problem – Problem Analysis Chart
Developing the Hierarchy Input Process Output (HIPO) chart
Developing the Input Process Output Chart
Drawing the program flowcharts
Writing the algorithms
29/10/2025 [Link] Nagaraju, SCOPE, VIT 38
Problem Solving by Computer- PAC
Analyzing the Problem – Problem Analysis Chart/Diagram
PAC is used as basis in establishing method of coding, testing, and data type description
Understand and analyze the problem to determine whether it can be solved by a computer.
• Analyze the requirements of the problem.
• Identify the following:
Data requirement (DATA)
Processing requirement or procedures that will be needed to solve the problem
(PROCESS)
The output (INFORMATION)
29/10/2025 [Link] Nagaraju, SCOPE, VIT 39
Problem Solving -PAC
Output Solution
Data Processing Alternatives
given in
the List of
proble List of ideas
m processi for the
ng Output
or requirem solutio
required n of
ent
or the
provide proble
d by procedu
res m
the
user
29/10/2025 [Link] Nagaraju, SCOPE, VIT 40
PAC – example1
• Payroll Problem
Calculate the salary of an employee who works by hourly basis. The formula to be
used is
Salary = Hour works * Pay rate
Solution
Data Processing Output Alternative
s
1. Define the
hours worked
Hours Salary = and pay rate as
work, constants.
Hours work Salary 2. Define the
Pay rate * pay rate hours worked
and pay rate as
input values.
29/10/2025 [Link] Nagaraju, SCOPE, VIT 41
PAC – Example2
• Write a Problem Analysis Chart (PAC) to convert the distance
in miles to kilometers where 1.609 kilometers per mile.
Alternate
Data Processi Output Alternate
Solutions
ng Solutions
1. Define
1. Define [Link]
Distanc thethe miles the miles
miles
Kilomete Distanc as as as
e in rs = e in constants constants
constants
miles 1.609 x kilomete . . .
miles rs ∗2.
∗2. ∗2.
29/10/2025 [Link] Nagaraju, SCOPE, VIT Define
Definethethe Define42 the
PAC – example3
• Write a Problem Analysis Chart (PAC) to find an area of a circle
where area = pi * radius * radius
Data Processi Output
Processi Output
ng
ng
area =
radius 3.14 x area
radius x
radius
29/10/2025 [Link] Nagaraju, SCOPE, VIT 43
Problem Solving by Computer- HIPO
Developing the Hierarchy Input Process Output (HIPO) or
Interactivity Chart
When problem is normally big and complex.
Processing can be divided into subtasks called modules.
Each module accomplishes one function.
These modules are connected to each other to show the interaction of
processing between the modules.
Main/control module controls the flow of all other modules.
29/10/2025 [Link] Nagaraju, SCOPE, VIT 44
Problem Solving by Computer- HIPO
Programming which use this approach (problem is divided into
subtasks) is called Structured Programming.
Main
Module
Module-1 Module-2
Module 4 Module 5 Module 6
29/10/2025 [Link] Nagaraju, SCOPE, VIT 45
Problem Solving by Computer- HIPO
HIPO chart for Payroll problem
PAYROLL
READ CALCULATE PRINT
29/10/2025 [Link] Nagaraju, SCOPE, VIT 46
Problem Solving by Computer- HIPO
Extended Payroll problem
• Write a program to calculate both the gross pay and the net pay of
every employee of your company. Use the following formulae for
calculation:
Gross pay = number of hours worked * pay rate
Net pay = gross pay – deductions
• The program should also print the cheque that tells the total net pay.
29/10/2025 [Link] Nagaraju, SCOPE, VIT 47
Problem Solving by Computer- HIPO
Extended Payroll problem -PAC
Input Processing Output
Number of Gross pay = Net pay
hours number of and write
worked, hours * pay rate net pay
pay rate, in
Net pay =
deduction cheque
Gross pay –
s deductions
29/10/2025 [Link] Nagaraju, SCOPE, VIT 48
Problem Solving by Computer- HIPO
Extended Payroll Problem -HIPO
Payroll
Calculate Calculate Write
Gross Pay Net Pay Cheque
Get
Get Calculate
Hourly
Pay rate Deductions
Worked
29/10/2025 [Link] Nagaraju, SCOPE, VIT 49
Developing an Algorithm
Algorithm is a step-by-step
procedure, which defines a set of
instructions to be executed in a
certain order to get the desired
output.
Algorithms are generally created
independent of underlying
languages, i.e. an algorithm can
be implemented in more than one
programming language.
Not all procedures can be called an algorithm
29/10/2025 [Link] Nagaraju, SCOPE, VIT 50
Developing an Algorithm
29/10/2025 [Link] Nagaraju, SCOPE, VIT 51
Developing an Algorithm cont…
• An algorithm should have the following characteristics −
1. Unambiguous − Algorithm should be clear and unambiguous. Each of its
steps (or phases), and their inputs/outputs should be clear and must lead to
only one meaning.
2. Input − An algorithm should have 0 or more well-defined inputs.
3. Output − An algorithm should have 1 or more well-defined outputs, and
should match the desired output.
4. Finiteness − Algorithms must terminate after a finite number of steps.
5. Feasibility − Should be feasible with the available resources.
6. Independent − An algorithm should have step-by-step directions, which
should be independent of any programming code.
29/10/2025 [Link] Nagaraju, SCOPE, VIT 52
Developing an Algorithm cont…
How to Write an Algorithm?
• There are no well-defined standards for writing algorithms.
• Rather, it is problem and resource dependent.
• Algorithms are never written to support a particular programming code.
• As we know that all programming languages share basic code constructs like
loops (do, for, while), flow-control (if-else), etc.
• These common constructs can be used to write an algorithm.
• Sometimes algorithm writing is a process and is executed after the problem
domain is well-defined.
• That is, we should know the problem domain, for which we are designing a
solution.
29/10/2025 [Link] Nagaraju, SCOPE, VIT 53
Developing an Algorithm cont…
• Example
• Problem − Design an algorithm to add two numbers and display the result.
• step 1 − START
• step 2 − declare three integers a, b & c
• step 3 − define values of a & b
• step 4 − add values of a & b
• step 5 − store output of step 4 to c
• step 6 − print c
• step 7 − STOP
29/10/2025 [Link] Nagaraju, SCOPE, VIT 54
Developing an Algorithm cont…
• Algorithms tell the programmers how to code the program.
• Alternatively, the algorithm can be written as −
• step 1 − START ADD
• step 2 − get values of a & b
• step 3 − c ← a + b
• step 4 − display c
• step 5 − STOP
• In design and analysis of algorithms, usually the second method is used to
describe an algorithm.
• It makes it easy for the analyst to analyze the algorithm ignoring all unwanted
definitions.
29/10/2025 [Link] Nagaraju, SCOPE, VIT 55
Developing an Algorithm cont…
• He can observe what operations are being used and how the process is
flowing.
• Writing step numbers, is optional.
• We design an algorithm to get a solution of a given problem.
• A problem can be solved in more than one ways.
29/10/2025 [Link] Nagaraju, SCOPE, VIT 56
Flowcharts
• Flowcharts graphically represent the flow of a program.
• There are four basic shapes used in a flow chart.
• Each shape has a specific use:
• oval: start / end
• parallelogram: input / output
• rectangle: calculations
• diamond: selection structures
29/10/2025 [Link] Nagaraju, SCOPE, VIT 57
Flowcharts cont…
Symbol Symbol Name Purpose
Used at the beginning and end of the
Start/Stop algorithm to show start and end of the
program.
Indicates processes like mathematical
Process operations.
Used for denoting program inputs and
Input/Output outputs.
Stands for decision statements in a
Decision program, where answer is usually Yes or
No.
29/10/2025 [Link] Nagaraju, SCOPE, VIT 58
Flowcharts cont…
Symbol Symbol Name Purpose
Arrow Shows relationships between different
shapes.
On-page Connects two or more parts of a
flowchart, which are on the same
Connector page.
Off-page Connects two parts of a flowchart
Connector which are spread over different pages.
29/10/2025 [Link] Nagaraju, SCOPE, VIT 59
Flowcharts cont…
• Guidelines for Developing Flowcharts
• Flowchart can have only one start and one stop symbol
• On-page connectors are referenced using numbers
• Off-page connectors are referenced using alphabets
• General flow of processes is top to bottom or left to right
• Arrows should not cross each other.
29/10/2025 [Link] Nagaraju, SCOPE, VIT 60
Flowcharts cont…
• Advantages of Flowchart:
• Flowcharts are a better way of communicating the logic of the system.
• Flowcharts act as a guide for blueprint during program designed.
• Flowcharts help in debugging process.
• With the help of flowcharts, programs can be easily analyzed.
• It provides better documentation.
• Easy to trace errors in the software.
• Easy to understand.
• The flowchart can be reused for inconvenience in the future.
• It helps to provide correct logic.
29/10/2025 [Link] Nagaraju, SCOPE, VIT 61
Flowcharts cont…
• Disadvantages of Flowchart:
• It is difficult to draw flowcharts for large and complex programs.
• There is no standard to determine the amount of detail.
• Difficult to reproduce the flowcharts.
• It is very difficult to modify the Flowchart.
• Making a flowchart is costly.
• If changes are done in software, then the flowchart must be redrawn.
29/10/2025 [Link] Nagaraju, SCOPE, VIT 62
Flowcharts cont…
• Arrows connect the basic shapes in a flowchart.
• The shapes and arrows of a flowchart describe the flow of a program from
start to end.
• Flowcharts typically flow from the top to the bottom or flow from the left to
the right.
• Below is the description of a simple program:
• The program starts.
• Then the program prints out "Output!".
• Finally, the program ends.
29/10/2025 [Link] Nagaraju, SCOPE, VIT 63
Flowcharts cont…
• A flowchart that describes this simple program is shown.
• The Python code that corresponds to this flowchart is:
# start
print("Output!")
# end
29/10/2025 [Link] Nagaraju, SCOPE, VIT 64
Flowcharts cont…
• A description of a program that includes a calculation is below:
The program starts.
Next, the program asks a user for a number.
Two is added to the number.
Next, the resulting sum is printed.
Finally, the program ends.
29/10/2025 [Link] Nagaraju, SCOPE, VIT 65
Flowcharts cont…
• The Python code that corresponds to this flow chart is:
# start
num = input("Enter a number: ")
num = float(num)
num_plus_2 = num + 2
print(num_plus_2)
# end
29/10/2025 [Link] Nagaraju, SCOPE, VIT 66
Flowcharts cont…
29/10/2025 [Link] Nagaraju, SCOPE, VIT 67
Flowcharts cont…
29/10/2025 [Link] Nagaraju, SCOPE, VIT 68
Flowcharts cont…
29/10/2025 [Link] Nagaraju, SCOPE, VIT 69
Flowcharts cont…
29/10/2025 [Link] Nagaraju, SCOPE, VIT 70
Flowcharts cont…
29/10/2025 [Link] Nagaraju, SCOPE, VIT 71
Flowcharts cont…
29/10/2025 [Link] Nagaraju, SCOPE, VIT 72
Pseudocode
• Pseudocode is a method of planning which enables the programmer to plan without
worrying about syntax.
• It’s simply an implementation of an algorithm in the form of annotations and
informative text written in plain English.
• It has no syntax like any of the programming language and thus can’t be compiled or
interpreted by the computer.
• Pseudocode, as the name suggests, is a false code or a representation of code which
can be understood by even a layman with some school level programming knowledge.
• Pseudocode is a term which is often used in programming and algorithm based fields.
• It is a methodology that allows the programmer to represent the implementation of an
algorithm.
29/10/2025 [Link] Nagaraju, SCOPE, VIT 73
Pseudocode cont…
• Advantages of Pseudocode
• Improves the readability of any approach.
• It’s one of the best approaches to start implementation of an algorithm.
• Acts as a bridge between the program and the algorithm or flowchart.
• Also works as a rough documentation, so the program of one developer can
be understood easily when a pseudo code is written out.
• In industries, the approach of documentation is essential. And that’s where a
pseudo-code proves vital.
• The main goal of a pseudo code is to explain what exactly each line of a
program should do, hence making the code construction phase easier for the
programmer.
29/10/2025 [Link] Nagaraju, SCOPE, VIT 74
Pseudocode cont…
• Five major steps in Python pseudocode
• The pseudocode in python must be line by line so every statement involved
must be represented as just one single line in pseudocode.
• Just as in python code how indentations are used, these indentations must be
preferred in python pseudocode too.
• Ensure that each statement of the pseudocode is simple and easy to
understand.
• Ensure the first word of the pseudocode is always in Upper case letters.
29/10/2025 [Link] Nagaraju, SCOPE, VIT 75
Pseudocode cont…
• Special Keyword:
• START: To begin the pseudocode.
• INPUT: Take input from the user.
• PRINT: To print the output on the screen.
• READ/GET: Input format while reading data from the file.
• SET, INIT: Initialize a value.
• INCREMENT, BUMP: Increase the value of the variable, equivalent to a++.
• DECREMENT: Decrease the value of the variable, equivalent to a--.
• COMPUTE, CALCULATE, DETERMINE: To calculate the expression result.
29/10/2025 [Link] Nagaraju, SCOPE, VIT 76
Pseudocode cont…
29/10/2025 [Link] Nagaraju, SCOPE, VIT 77
Pseudocode cont…
• Write the FizzBuzz Algorithm Using pseudocode
• FizzBuzz is a standard coding, in which we write a code to print Fizz, Buzz, and
FizzBuzz when the multiple of 3 and 5 occurs.
• The problem states:
• Write a code that prints each number from 1 to 30 in a new line.
• Print "Fizz" if the number is the multiple of 3.
• Print "Buzz" if the number is a multiple of 5.
• For a number that is multiple of both 3 and 5 print “FizzBuzz.”
29/10/2025 [Link] Nagaraju, SCOPE, VIT 78
Pseudocode cont…
• FizzBuzz Pseudocode
num : 1
FOR num -> 1 to 20
IF num MOD 15 ==0
PRINT “FizzBuzz”
ELSE IF num MOD 3 ==0
PRINT “Fizz”
ELSE IF num MOD 5==0
PRINT “Buzz”
ELSE PRINT num
ENDIF
29/10/2025 [Link] Nagaraju, SCOPE, VIT 79
ENDFOR
Pseudocode cont…
• Equivalent Python Code:
for num in range(1, 21):
if num % 15 ==0:
print("FizzBuzz")
elif num %3 ==0:
print("Fizz")
elif num %5==0:
print("Buzz")
else:
print(num)
29/10/2025 [Link] Nagaraju, SCOPE, VIT 80
Pseudocode cont…
• Python pseudocode Examples
• Retrieve the number to be reversed from the user into variable
sample_number.
• Initialize the temporary variable test_number as zero.
• Perform a while loop until the sample_number variable is greater than zero.
• Modulus the sample_number variable by 10 and store the remainder.
• Multiply the temporary number of test_number by 10 and add the returned
value to the remainder.
• Print the generated test_number onto the console.
29/10/2025 [Link] Nagaraju, SCOPE, VIT 81
Pseudocode cont…
• Pseudocode:
sample_number = int(input("Number to be reversed: "))
test_number = 0
while(sample_number>0):
remainder_number = sample_number % 10
test_number = (test_number * 10) + remainder_number
sample_number = sample_number//10
print("Value after reverse : {}".format(test_number))
29/10/2025 [Link] Nagaraju, SCOPE, VIT 82
Pseudocode cont…
• WRITE A PSEUDOCODE TO FIND THE LARGEST OF TWO NUMBERS.
BEGIN
NUMERIC nNum1,nNum2
DISPLAY "ENTER THE FIRST NUMBER : "
INPUT nNum1
DISPLAY "ENTER THE SECOND NUMBER : "
INPUT nNum2
IF nNum1 > nNum2
DISPLAY nNum1 + " is larger than "+ nNum2
ELSE
DISPLAY nNum2 + " is larger than " + nNum1
29/10/2025 [Link] Nagaraju, SCOPE, VIT 83
END
Pseudocode cont…
• WRITE A PSEUDOCODE TO FIND THE SUM OF TWO NUMBERS.
begin
numeric nNum1,nNum2,nSum
display "ENTER THE FIRST NUMBER : "
accept nNum1
display "ENTER THE SECOND NUMBER : "
accept nNum2
compute nSum=nNum1+nNum2
display "SUM OF THESE NUMBER : " nSum
end
29/10/2025 [Link] Nagaraju, SCOPE, VIT 84
Pseudocode cont…
• WRITE A PSEUDOCODE TO FIND THE AREA OF RECTANGLE.
begin
numeric nLen,nBrd,nAre
display "ENTER THE LENGTH OF RECTANGLE : "
accept nLen
display "ENTER THE BREADTH OF RECTANGLE : "
accept nBrd
nAre=nLen*nBrd
display "AREA OF RECTANGLE : " nAre
end
29/10/2025 [Link] Nagaraju, SCOPE, VIT 85
Pseudocode cont…
• WRITE A PSEUDOCODE TO FIND THE GREATEST OF TWO NUMBERS.
begin
numeric nNum1, nNum2
display "ENTER THE FIRST NUMBER : "
accept nNum1
display "ENTER THE SECOND NUMBER : "
accept nNum2
if(nNum1>nNum2)
begin
display "GREATEST ONE : " nNum1
end
else
begin
display "GREATEST ONE : " nNum2
end
29/10/2025 [Link] Nagaraju, SCOPE, VIT 86
end
Conclusion
• To design an algorithm you can draw a flowchart or write pseudo-
code.
• Your algorithm (flowchart or pseudo-code) can then be converted by
a programmer using the programming language of their choice (e.g.
Python, Java, Visual Basic, etc.).
29/10/2025 [Link] Nagaraju, SCOPE, VIT 87
29/10/2025 [Link] Nagaraju, SCOPE, VIT 88
29/10/2025 [Link] Nagaraju, SCOPE, VIT 89
29/10/2025 [Link] Nagaraju, SCOPE, VIT 90