BACSE101 Problem Solving
using Python
Dr. Ramesh Babu Vemuluri,
SMEC,
Vellore Institute of Technology, Vellore
Module 1: Introduction to
Problem Solving and Python
Fundamentals cont…
Contents
• Introduction
• Binary code
• Logic Gates
• Python Programming
• Problem solving - Definition and steps
• Problem Analysis Chart (PAC)
• Developing an Algorithm
• Flowchart
• Pseudocode
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 3
Binary Code
• In the coding, when numbers, letters or words are represented by a specific
group of symbols, it is said that the number, letter or word is being encoded.
• The group of symbols is called as a code.
• The digital data is represented, stored and transmitted as group of binary
bits. This group is also called as binary code.
• The binary code is represented by the number as well as alphanumeric
letter.
• Digital data is described, saved, and communicated as sets of binary digits
which are known as bits. The set of bits is called binary code.
• Binary codes are used in devices as they enable computers to implement
complex evaluations fastly and effectively.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 4
Binary Code cont.
• Binary codes are suitable for the computer applications.
• Binary codes are suitable for the digital communications.
• Binary codes make the analysis and designing of digital circuits if we use the
binary codes.
• Since only 0 & 1 are being used, implementation becomes easy.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 5
Binary Code cont.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 6
Binary Code cont.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 7
Binary Code cont.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 8
Logic Gates
• Logic gates are building blocks of the digital system.
• Logic gates are small digital switching circuit that determines the output of
two or more inputted functions in Binary format.
• Logical ‘1’ means ‘True’ or ‘High’ in nature, whereas logical ‘0’ means ‘False’
or ‘Low’ in nature.
• Based on different logical operations, the output differs.
• There can be many inputs in a logic gate but there will be only one output.
• Each logic gate has its own truth table which represents all the combinations
of input and output.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 9
Logic Gates cont.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 10
Logic Gates cont.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 11
Python Programming
• The main function of a computer processor is to execute instructions and
produce an output.
• CPU work Fetch, Decode, and Execute are the fundamental functions of the
computer.
• Fetch: the first CPU gets the instruction. That means binary numbers that
are passed from RAM to CPU.
• Decode: When the instruction is entered into the CPU, it needs to decode
the instructions with the help of ALU (Arithmetic Logic Unit), the process of
decoding begins.
• Execute: After the decode step the instructions are ready to execute.
• Store: After the execute step the instructions are ready to store in the
memory.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 12
Python Programming cont…
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 13
Python Programming cont…
• CPU performance is how fast a computer’s processor (CPU) can complete
the task.
• It is measured by the number of instructions completed in one second.
• Its performance depends on the processor’s clock speed and other factors
like its design and the size of its cache.
• A computer program is a set of instructions written by a programmer that
tells a computer what to do.
• For example, Using a web browser or a word processor is a program,
performing math operations on a computer and clicking and selecting items
with a mouse or touchpad is also a program.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 14
Python Programming cont…
• Python is an example of a high-level language, other high-level languages are
C, C++, Perl and Java.
• There are also Low-level languages, also called as machine language or
assembly languages.
• Computers can execute programs written in low-level languages.
• Programs written in a high-level language take less time to write, shorter and
easier to read, and editable.
• Portable- can run on different kinds of computers with few or no
modifications.
• Low-level programs can run on only one kind of computer and have to be
rewritten to run on another.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 15
Python Programming cont…
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 16
Python Programming cont…
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 17
Python Programming cont…
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 18
Python Programming cont…
• Python is an interpreter and compiler
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 19
Python Programming Cont..
• Compiler: A compiler translates code from a high-level programming
language into machine code before the program runs.
• Interpreter: An interpreter translates code written in a high-level
programming language into machine code line-by-line as the code runs.
Compiler
• A language processor that converts a program written in high-level language
into machine language, entire program at once, is called a compiler.
• Thus, the input of a compiler is a high-level language code (called source
code), while its output is a machine language code (called object code).
• A compiler scans whole program and then check it for syntactic and semantic
error, once the code is checked for errors, it is converted into an object code.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 20
Python Programming Cont..
Compiler
• Then, it can be processed by the machine to perform the corresponding task.
• The common programming languages that use compiler are C, C++, C#, JAVA,
etc.
• A compiler translates a program in a single run.
• It consumes less time.
• CPU utilization is more.
• Both syntactic and semantic errors can be checked concurrently.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 21
Python Programming Cont..
Interpreter
• A language translator that converts a high-level language program into a
machine language program, one line at a time.
• Interpreters converts the codes slower than compiler.
• This is because the interpreter can scan and translate only one statement of
the program at a time.
• Therefore, interpreters convert the source code into machine code during the
execution of the program.
• Interpreters do not generate an object code corresponding to the source code.
• However, these are relatively easy to use and execute the code. The
programming languages that use interpreters are Perl, Ruby, Python, MATLAB,
etc.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 22
Python Programming Cont..
Interpreter
• An interpreter translates the program line by line.
• The interpreter is smaller in size.
• It is flexible.
• Error localization is easier.
• The interpreter facilitates the implementation of computer programming
language constructs.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 23
Python Programming Cont..
Parameter Compiler Interpreter
The program is
Compilers scan the entire
Program scanning interpreted/translated
program in one go.
one line at a time.
As and when scanning is One line of code is
performed, all the errors scanned, and errors
Error detection
are shown in the end encountered are
together, not line by line. shown.
Interpreters do not
Compilers convert the
Object code convert the source
source code to object code.
code into object code.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 24
Python Programming Cont..
Parameter Compiler Interpreter
It is not preferred due to its
The execution time of slow speed. Usually,
Execution time compiler is less, hence it is interpreter is slow, and
preferred. hence takes more time to
execute the object code.
Compiler doesn’t require the
Need of source It requires the source code
source code for execution
code for execution later.
later.
Interpreters are smaller in
Size Compiler are larger in size.
size.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 25
Python Programming Cont..
Parameter Compiler Interpreter
Programming languages
Programming languages that
Programming that uses interpreter
use compilers include C, C++,
languages include Python, Ruby, Perl,
C#, etc..
MATLAB, etc.
Compiler can check syntactic
Types of errors Interpreter checks the
and semantic errors in the
detected syntactic errors only.
program simultaneously.
Interpreters are relatively
Flexibility Compilers are not flexible.
flexible.
Interpreters are less
Efficiency Compilers are more efficient.
efficient.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 26
Python Programming Cont..
• 4 Types of Interpreters
• Bytecode interpreter
• Threaded code interpreter
• Abstract syntax tree interpreter
• Justin-in-time compilation
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 27
Python Programming Cont..
• 10 Types of Compilers
• Cross-compiler
• Native compiler
• Bootstrap compiler
• Decompiler
• Source-to-source compiler
• Language rewriter
• Bytecode compiler
• Just-in-time compiler
• AOT compilation, and Assembler
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 28
Python Programming Cont..
• A program is a sequence of instructions that specifies how to perform a
computation for solving certain problems.
• Problems that can be solved on computers generally consists of only three:
1) Computational, problems involving some kind of mathematical processing;
2) Logical, problems involving relational or logical processing, the kinds of
processing used in decision making on the computer; and
3) Repetitive, problems involving repeating a set of mathematical and/or
logical instructions. Search problems, and counting problems.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 29
Debugging
• Programming is error-prone.
• For whimsical reasons, programming errors are called bugs and the process of
tracking them down is called debugging.
• Three kinds of errors can occur in a program: syntax errors, runtime errors,
and semantic errors.
• Syntax refers to the structure of a program and the rules about that structure.
• Syntax errors: python can only execute a program if the syntax is correct;
otherwise, the interpreter displays an error message.
• Runtime error: the error does not appear until after the program has started
running.
• These errors are also called exceptions because they usually indicate that
something exceptional has happened.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 30
• Semantic errors: it will run successfully in the sense that the computer will not
generate any error messages, but it will not do the right thing.
• It will do something else.
• The meaning of the program (its semantics) is wrong.
• Identifying sematic errors can be tricky because it requires you to work
backward by looking at the output of the program and trying to figure out
what it is doing.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 31
Problem Solving in Python
• Problem-solving is the process of identifying a problem, creating an algorithm
to solve the given problem, and finally implementing the algorithm to develop
a computer program.
• An algorithm is a process or set of rules to be followed while performing
calculations or other problem-solving operations.
• It is simply a set of steps to accomplish a certain task.
• There are 5 major steps for efficient problem-solving.
1. Understanding the Problem
2. Exploring Examples
3. Breaking the Problem Down
4. Solving or Simplification
5. Looking back and Refactoring
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 32
Problem Solving in Python cont…
Step 1 – Understanding the Problem
• While understanding the problem, we first need to closely examine the
language of the question and then proceed further.
• What are the inputs that are needed for the problem?
• What are the outputs that come from the problem?
• Can the outputs be determined from the inputs? In other words, do we have
enough information to solve the given problem?
Step 2 – Explore Examples
• Once we have understood the given problem, we can look up various
examples related to it.
• The examples should cover all situations that can be encountered while the
implementation.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 33
Problem Solving in Python cont…
Step 3 – Breaking the Problem Down
• After exploring examples related to the problem, we need to break down the
given problem.
• Before implementation, we write out the steps that need to be taken to solve
the question.
Step 4 – Solving or Simplification
• Once we have laid out the steps to solve the problem, we try to find the
solution to the question.
• If the solution cannot be found, try to simplify the problem instead.
• The steps to simplify a problem are as follows:
• Find the core difficulty
• Temporarily ignore the difficulty
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 34
Problem Solving in Python cont…
• Write a simplified solution
• Then incorporate that difficulty
Step 5 – Looking back and Refactoring
• Since we have completed the implementation of the problem, we now look
back at the code and refactor it if required.
• It is an important step to refactor the code so as to improve efficiency.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 35
Problem Analysis Chart (PAC)
Data Processing Output
Given in the problem or List of processing Output
Provided by the user. required or procedures requirement.
or logic.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 36
Problem Analysis Chart (PAC) cont…
• Write a PAC to find an area of a circle where area = pi * radius * radius
Data Processing Output
radius Area = 3.14 x radius x area
radius
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 37
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.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 38
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.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 39
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.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 40
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
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 41
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.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 42
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.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 43
Flowcharts
• Flowcharts are nothing but the graphical representation of the data or the
algorithm for a better understanding of the code visually.
• It displays step-by-step solutions to a problem, algorithm, or process.
• It is a pictorial way of representing steps that are preferred by most beginner-
level programmers to understand algorithms of computer science, thus it
contributes to troubleshooting the issues in the algorithm.
• A flowchart is a picture of boxes that indicates the process flow sequentially.
• Since a flowchart is a pictorial representation of a process or algorithm, it’s
easy to interpret and understand the process.
• To draw a flowchart, certain rules need to be followed which are followed by
all professionals to draw a flowchart and are widely accepted all over the
countries.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 44
Flowcharts cont…
• There are four basic shapes used in a flow chart.
• Each shape has a specific use:
• oval: start / end/ Terminal / Terminator
• parallelogram: data/ input / output
• rectangle: calculations/ process
• diamond: Selection Structures / Decision
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 45
Flowcharts cont…
• A flowchart is a graphical representation of an algorithm.it should follow
some rules while creating a flowchart
Rule 1: Flowchart opening statement must be ‘start’ keyword.
Rule 2: Flowchart ending statement must be ‘end’ keyword.
Rule 3: All symbols in the flowchart must be connected with an arrow line.
Rule 4: The decision symbol in the flowchart is associated with the arrow line.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 46
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
Action / 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.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 47
Flowcharts cont…
Symbol Symbol Name Purpose
Shows relationships between different
Arrow
shapes.
Connects two or more parts of a
On-page
flowchart, which are on the same
Connector
page.
Off-page Connects two parts of a flowchart
Connector which are spread over different pages.
Multiple Represents multiple documents in the
documents symbol process.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 48
Flowcharts cont…
Symbol Symbol Name Purpose
document A printed document or report.
Represents a step where a user is
Manual input prompted to enter information
manually.
Represents a set-up to another step in
preparation
the process.
Indicates that the process flow
Or
continues in more than two branches.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 49
Flowcharts cont…
Symbol Symbol Name Purpose
Indicates a point in the flowchart where
Summoning
multiple branches converge back into a
Junction
single process.
Indicates a step where two or more
Merge
sub-lists or sub-processes become one.
Indicates a step that orders information
Collate
into a standard format.
Indicates a step that organizes a list of
Sort items into a sequence or sets based on
some pre-determined criteria.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 50
Flowcharts cont…
Symbol Symbol Name Purpose
Indicates a sequence of actions that
perform a specific task embedded
Subroutine within a larger process. This sequence
of actions could be described in more
detail on a separate flowchart.
Indicates a sequence of commands that
Manual Loop will continue to repeat until stopped
manually.
Indicates the point at which a loop
Loop Limit should stop.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 51
Flowcharts cont…
Symbol Symbol Name Purpose
Delay Indicates a delay in the process.
Data Storage or Indicates a step where data gets stored.
Stored Data
Indicates a list of information with a
Database standard structure that allows for
searching and sorting.
Indicates that information was stored in
Internal Storage memory during a program, used in
software design flowcharts.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 52
Flowcharts cont…
Symbol Symbol Name Purpose
Display Indicates a step that delay information.
Indicates that the process continues off
Off Page page.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 53
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.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 54
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.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 55
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.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 56
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.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 57
Flowcharts cont…
• Flow chart conventions-
Sequential Structure
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 58
Flowcharts cont…
• Flow chart conventions-
Selection Structure
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 59
Flowcharts cont…
• Flow chart conventions-
Repetition Structure
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 60
Flowcharts cont…
• A flowchart that describes this simple program is shown.
• The Python code that corresponds to this flowchart is:
# start
print("Output!")
# end
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 61
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.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 62
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
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 63
Flowcharts cont…
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 64
Flowcharts cont…
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 65
Flowcharts cont…
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 66
Flowcharts cont…
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 67
Flowcharts cont…
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 68
Flowcharts cont…
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 69
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.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 70
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.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 71
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.
• Ensure to use periods and delimiters wherever needed.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 72
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.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 73
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 20 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.”
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 74
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
ENDFOR
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 75
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)
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 76
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.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 77
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))
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 78
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
END
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 79
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
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 80
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
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 81
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
end
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 82
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.).
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 83
Practice
• 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.).
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 84
Practice- Volume of a sphere
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 85
Practice- Convert Celsius to Fahrenheit degree
F = (9/5) *C+32.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 86
Practice- Convert inches to centimeters
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 87
Practice- exchanges the values of two variables
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 88
Excercise
1. Draw a flowchart to find the sum of first 50 natural numbers.
2. Write algorithm and pseudocode for the above problem.
3. Draw a flowchart to calculate the area of a circle.
4. Write algorithm and pseudocode for the above problem.
5. Draw a flowchart to check whether a year is a leap year or not.
6. Write algorithm and pseudocode for the above problem.
31-07-2025 Dr Ramesh Babu Vemuluri, VIT Vellore 89