ALGORITHMIC THINKING WITH PYTHON
MODULE - 2
ALGORITHM AND PSEUDOCODE REPRESENTATION, FLOWCHARTS
3 – MARK QUESTIONS & ANSWERS
Q#1: Explain pseudocode. How is it different from a programming language?
Answer:
Pseudocode is a human-readable description of an algorithm written in a structured format
resembling programming languages but without strict syntax rules.
It helps in designing logic before actual coding.
Differences:
Aspect Pseudocode Programming Language
Purpose To design and plan logic To implement code for execution
Syntax Not strict Strictly follows grammar rules
Execution Cannot be executed Can be executed by interpreter/compiler
Example IF mark >= 40 THEN print "Pass" if mark >= 40: print("Pass")
Q#2: Explain any three reasons why pseudocode is widely used in problem solving.
Answer:
1. Simplicity: Pseudocode is easy to write and understand.
2. Focus on Logic: It emphasizes logic rather than syntax.
3. Language Independence: Can be used by programmers of any language.
4. Improves Debugging: Helps identify logic errors before coding.
5. Serves as Blueprint: Guides actual program development.
Prepared By: Prof. Filson P. Rajan
St. Thomas College of Engineering & Technology, Kozhuvalloor
ALGORITHMIC THINKING WITH PYTHON
Q#3: Develop a pseudocode to input two numbers and display their sum.
Answer:
Pseudocode:
START
READ num1, num2
sum ← num1 + num2
PRINT "Sum =", sum
STOP
Q#4: Explain Algorithm with a suitable example.
Answer:
An Algorithm is a step-by-step set of instructions for solving a specific problem.
Example: Algorithm to find the sum of two numbers
1. Start
2. Read two numbers a and b
3. Compute sum = a + b
4. Print the sum
5. Stop
Q#5: Explain with example how sequencing is represented in a flowchart.
Answer:
Sequencing means executing statements one after another in a fixed order.
In a flowchart, this is represented by a series of process boxes connected by arrows.
Example:
Start → Input A, B → Sum = A + B → Print Sum → Stop
Prepared By: Prof. Filson P. Rajan
St. Thomas College of Engineering & Technology, Kozhuvalloor
ALGORITHMIC THINKING WITH PYTHON
Q#6: Create pseudocode using an if–else structure to check whether a number is positive or
negative.
Answer:
Pseudocode:
START
READ num
IF num > 0 THEN
PRINT "Positive"
ELSE
PRINT "Negative"
ENDIF
STOP
Q#7: Create an algorithm to accept the name of a student, mark and check whether he passed or
failed. (if mark ≥ 40, he passed, else, failed)
Answer:
Algorithm:
1. Start
2. Input name and mark
3. If mark ≥ 40, then
Print “Pass”
Else
Print “Fail”
4. Stop
Q#8: Develop a pseudocode to find the largest among three numbers.
Answer:
Pseudocode:
START
READ a, b, c
IF a > b AND a > c THEN
PRINT "A is largest"
ELSE IF b > c THEN
PRINT "B is largest"
ELSE
PRINT "C is largest"
ENDIF
STOP
Prepared By: Prof. Filson P. Rajan
St. Thomas College of Engineering & Technology, Kozhuvalloor
ALGORITHMIC THINKING WITH PYTHON
Q#9: Develop an algorithm for accepting two numbers and take sum of it.
Answer:
Algorithm:
1. Start
2. Input a, b
3. Compute sum = a + b
4. Print sum
5. Stop
Q#10: Explain the purpose of flowlines in a flowchart with an example.
Answer:
Flowlines are arrows used in a flowchart to show the direction of control from one step to
another.
They connect different symbols like input/output, process, and decision boxes.
Example:
Start → Input A → Process (A=A+1) → Print A → Stop
Q#11: Develop pseudocode to print numbers from 1 to 10 using a for loop.
Answer:
Pseudocode:
START
FOR i = 1 TO 10 DO
PRINT i
ENDFOR
STOP
Q#12: Draw and explain the flowchart symbols for: Start/End, Input/Output, and Decision.
Answer:
Symbol Shape Purpose
Start/End Oval Indicates beginning or end of flowchart
Input/Output Parallelogram Used for reading or displaying data
Diamond Represents a condition with Yes/No
Decision
path
Prepared By: Prof. Filson P. Rajan
St. Thomas College of Engineering & Technology, Kozhuvalloor
ALGORITHMIC THINKING WITH PYTHON
4 - MARK QUESTIONS & ANSWERS
Q#1: Draw a flowchart to add two numbers.
Answer:
Flowchart Description:
1. Start
2. Input two numbers A and B
3. Compute sum = A + B
4. Display the sum
5. Stop
Flowchart
Start
Input A, B
sum = A + B
Print sum
Stop
Prepared By: Prof. Filson P. Rajan
St. Thomas College of Engineering & Technology, Kozhuvalloor
ALGORITHMIC THINKING WITH PYTHON
Q#2: Define the purpose of decision construct in pseudocode. Give one example.
Answer:
A decision construct allows a program to make choices based on a condition.
It uses structures like IF–ELSE to execute different blocks depending on whether the condition is
True or False.
Example:
IF mark >= 40 THEN
PRINT "Pass"
ELSE
PRINT "Fail"
ENDIF
Purpose:
Decision constructs enable logical branching and control program flow depending on conditions.
Q#3: Develop an algorithm to find the sum of two numbers a and b.
Answer:
Algorithm:
1. Start
2. Input a, b
3. Compute sum = a + b
4. Print sum
5. Stop
Explanation:
This simple algorithm performs addition by reading two inputs and displaying their sum.
Prepared By: Prof. Filson P. Rajan
St. Thomas College of Engineering & Technology, Kozhuvalloor
ALGORITHMIC THINKING WITH PYTHON
Q#4: Explain flowchart with a real-time example.
Answer:
A flowchart is a visual representation of the steps in an algorithm using symbols and arrows.
Advantages:
• Easy to understand logic
• Helps identify logical errors
• Serves as program documentation
Example: Flowchart for Checking Even or Odd Number
Start
Input n
Yes If n % 2 ==0 No
Print Even Print Odd
Stop
Prepared By: Prof. Filson P. Rajan
St. Thomas College of Engineering & Technology, Kozhuvalloor
ALGORITHMIC THINKING WITH PYTHON
Q#5: Develop a flowchart for a student grading system that reads marks, calculates average, and
assigns grades.
Answer:
Steps:
1. Start
2. Input marks in 3 subjects
3. Calculate average = (m1 + m2 + m3)/3
4. Decision:
o If avg ≥ 90 → Grade = A+
o Else if avg ≥ 70 → Grade = A
o Else if avg ≥ 50 → Grade = B
o Else → Fail
5. Print grade
6. Stop
Flowchart
Start
Input m1, m2, m3
avg = (m1+m2+m3)/3
If avg >=90 Yes Print Grade A+
No
Yes
If avg >=70 Print Grade A
No
If avg >=50 Yes
Print Grade B
No
Print Failed Stop
Prepared By: Prof. Filson P. Rajan
St. Thomas College of Engineering & Technology, Kozhuvalloor
ALGORITHMIC THINKING WITH PYTHON
Q#6: Draw a flowchart to calculate and print the product of the first N natural numbers.
Answer:
Algorithm:
1. Start
2. Input N
3. Set product = 1 and i = 1
4. While i ≤ N, do
product = product * i
i = i + 1
5. Print product
6. Stop
Flowchart
Start
Input N
product =1
i=1
No
i <=N Print product
Yes
product =product *i Stop
i= i +1
Prepared By: Prof. Filson P. Rajan
St. Thomas College of Engineering & Technology, Kozhuvalloor
ALGORITHMIC THINKING WITH PYTHON
Q#7: Create an algorithm to read three numbers and print the largest.
Answer:
Algorithm:
1. Start
2. Input a, b, c
3. If a > b and a > c → Print “A is largest”
Else if b > c → Print “B is largest”
Else → Print “C is largest”
4. Stop
Q#8: Develop an algorithm for finding area of a rectangle.
Answer:
Algorithm:
1. Start
2. Input length (L) and breadth (B)
3. Calculate area = L × B
4. Print area
5. Stop
Example:
If L = 5, B = 3 → area = 15
Q#9: Develop an algorithm for checking whether a candidate is eligible to vote. (if age ≥ 18)
Answer:
Algorithm:
1. Start
2. Input age
3. If age ≥ 18 → Print “Eligible to Vote”
Else → Print “Not Eligible”
4. Stop
Prepared By: Prof. Filson P. Rajan
St. Thomas College of Engineering & Technology, Kozhuvalloor
ALGORITHMIC THINKING WITH PYTHON
Q#10: Draw and explain the shapes used for Input, Output, Start, and Decision making in a
flowchart.
Answer:
Symbol Shape Meaning
Start/Stop Oval Beginning or ending point
Input/Output Parallelogram For reading or displaying data
Process Rectangle Computation or processing step
Decision Diamond Conditional branching
Q#11: Develop pseudocode for checking if a student has passed or failed. If score ≥ 40, student
will pass; else, fail.
Answer:
Pseudocode:
START
READ score
IF score >= 40 THEN
PRINT "Pass"
ELSE
PRINT "Fail"
ENDIF
STOP
Prepared By: Prof. Filson P. Rajan
St. Thomas College of Engineering & Technology, Kozhuvalloor
ALGORITHMIC THINKING WITH PYTHON
Q#12: Draw a flowchart to calculate the circumference of a circle using formula 2πr.
Answer:
Algorithm:
1. Start
2. Input radius r
3. Compute circumference = 2 × π × r
4. Print circumference
5. Stop
Flowchart
Start
Input r
circumference = 2 * 3.14 *r
Print circumference
Stop
Prepared By: Prof. Filson P. Rajan
St. Thomas College of Engineering & Technology, Kozhuvalloor
ALGORITHMIC THINKING WITH PYTHON
5 - MARK QUESTIONS & ANSWERS
Q#1: Explain pseudocode in detail with examples. Why is it preferred in algorithm design?
Answer:
Pseudocode is a simple, informal, human-readable representation of an algorithm that outlines
the steps required to solve a problem. It is written in plain English mixed with programming-like
constructs (IF, FOR, WHILE etc.) but is not executed by a computer.
Features:
• Uses simple English statements.
• No specific syntax or grammar.
• Focuses on logic rather than language rules.
Example:
START
READ num
IF num % 2 == 0 THEN
PRINT "Even"
ELSE
PRINT "Odd"
ENDIF
STOP
Reasons for Preference:
1. Easy to understand for both programmers and non-programmers.
2. Helps in designing algorithms before coding.
3. Reduces logical errors before implementation.
4. Simplifies debugging and documentation.
Prepared By: Prof. Filson P. Rajan
St. Thomas College of Engineering & Technology, Kozhuvalloor
ALGORITHMIC THINKING WITH PYTHON
Q#2: Develop pseudocode to read the marks of a student in 3 subjects, calculate the total and
average, and print the grade using an if–else structure.
Answer:
Pseudocode:
START
READ m1, m2, m3
total ← m1 + m2 + m3
average ← total / 3
IF average >= 90 THEN
grade ← "A+"
ELSE IF average >= 80 THEN
grade ← "A"
ELSE IF average >= 70 THEN
grade ← "B"
ELSE IF average >= 60 THEN
grade ← "C"
ELSE
grade ← "Fail"
ENDIF
PRINT total, average, grade
STOP
Q#3: Compare and contrast the if–else structure and the case structure in pseudocode. Give
suitable examples for each.
Answer:
Aspect If–Else Structure Case Structure
Used to select from multiple options based on
Definition Used to check conditions sequentially.
a single value.
Syntax Multiple IF and ELSE IF statements. Uses CASE or SWITCH with defined options.
Efficiency Suitable for range-based conditions. Suitable for fixed choices.
IF mark >= 40 THEN PRINT "Pass" CASE choice OF 1: PRINT "Add" 2: PRINT
Example ELSE PRINT "Fail" "Subtract" ENDCASE
Prepared By: Prof. Filson P. Rajan
St. Thomas College of Engineering & Technology, Kozhuvalloor
ALGORITHMIC THINKING WITH PYTHON
Q#4: Create pseudocode to generate the multiplication table of a number entered by the user.
(Use for loop)
Answer:
Pseudocode:
START
READ num
FOR i = 1 TO 10 DO
product ← num * i
PRINT num, "x", i, "=", product
ENDFOR
STOP
Explanation:
The loop runs 10 times, multiplying the input number by each integer from 1 to 10 and printing
the results.
Q#5: Create pseudocode to check whether a number entered is even or odd.
Answer:
Pseudocode:
START
READ num
IF num % 2 == 0 THEN
PRINT "Even Number"
ELSE
PRINT "Odd Number"
ENDIF
STOP
Explanation:
The modulo operator (%) checks divisibility by 2.
Prepared By: Prof. Filson P. Rajan
St. Thomas College of Engineering & Technology, Kozhuvalloor
ALGORITHMIC THINKING WITH PYTHON
Q#6: Explain any 5 differences between algorithm and flowchart.
Answer:
Aspect Algorithm Flowchart
Definition Step-by-step written instructions. Diagrammatic representation of an algorithm.
Form Textual (English-like statements). Visual (symbols & arrows).
Ease of
Easier for programmers. Easier for everyone to visualize.
Understanding
Error Detection Logical errors visible during writing. Logical flow errors easily spotted.
Modification Easier to edit or add steps. Requires redrawing for any change.
Q#7: Create the algorithm and draw a flowchart to check whether a given year is a leap year.
Answer:
Algorithm:
1. Start
2. Input year
3. If (year % 400 == 0) OR (year % 4 == 0 AND year % 100 != 0)
Print “Leap Year”
Else
Print “Not a Leap Year”
4. Stop
Flowchart
Start
Input year
If (year % 400 ==0)
OR
(year % 4== 0) And (year % 100 != 0)
Yes No
Print Leap Print Not Leap
Stop
Prepared By: Prof. Filson P. Rajan
St. Thomas College of Engineering & Technology, Kozhuvalloor
ALGORITHMIC THINKING WITH PYTHON
Q#8: Draw a flowchart to check whether a number is odd or even.
Answer:
Steps:
1. Start
2. Input number
3. Check condition: num % 2 == 0
4. If true → Print “Even”
Else → Print “Odd”
5. Stop
Flowchart
Start
Input num
Yes If num % 2 ==0 No
Print Even Print Odd
Stop
Prepared By: Prof. Filson P. Rajan
St. Thomas College of Engineering & Technology, Kozhuvalloor
ALGORITHMIC THINKING WITH PYTHON
Q#9: Develop the pseudocode for checking if the number is positive or negative.
Answer:
Pseudocode:
START
READ num
IF num > 0 THEN
PRINT "Positive Number"
ELSE IF num == 0 THEN
PRINT "Zero"
ELSE
PRINT "Negative Number"
ENDIF
STOP
Q#10: Discuss sequencing, selection/decision, and repetition/iteration flowcharts with examples
for each.
Answer:
1. Sequencing:
o Executes statements one after another.
o Example: Add two numbers → Start → Input A,B → A+B → Output → Stop.
2. Selection (Decision):
o Chooses between two or more paths based on condition.
o Example: Check Even/Odd using IF num%2==0.
3. Repetition (Iteration):
o Executes a set of instructions repeatedly.
o Example: Display numbers 1 to 10 using a loop.
**You Should DRAW Flowchart for each example (Three types of flowcharts are already
discussed in previous questions separately)
Prepared By: Prof. Filson P. Rajan
St. Thomas College of Engineering & Technology, Kozhuvalloor
ALGORITHMIC THINKING WITH PYTHON
Q#11: Develop a pseudocode to create a simple calculator to carry out addition, subtraction,
multiplication, and division.
Answer:
Pseudocode:
START
READ num1, num2
READ operator
IF operator == '+' THEN
result ← num1 + num2
ELSE IF operator == '-' THEN
result ← num1 - num2
ELSE IF operator == '*' THEN
result ← num1 * num2
ELSE IF operator == '/' THEN
result ← num1 / num2
ELSE
PRINT "Invalid Operator"
ENDIF
PRINT "Result =", result
STOP
Q#12: Differentiate between sequencing and selection in pseudocode with examples.
Answer:
Aspect Sequencing Selection
Execution of steps one after Execution of specific steps based on
Definition
another in a specific order. condition.
Control
Linear flow. Decision-based branching.
Flow
READ A, B → SUM = A + B → IF A > B THEN PRINT "A greater"
Example PRINT SUM ELSE PRINT "B greater"
Usage Used for continuous operations. Used for conditional checks.
Prepared By: Prof. Filson P. Rajan
St. Thomas College of Engineering & Technology, Kozhuvalloor