Introduction to Pseudocode
• Algorithm can be represented in the range of ways
• It can be represented by visually as a Flowchart or it can be represented
by text as a pseudocode.
Pseudocode
• Pseudocode is a method of expressing an algorithm design.
• Pseudocode is lines of instructions written in a language close to English.
• Pseudocode as it normally doesn’t resemble any one programming language.
• There are no definitive rules for writing pseudocode but it should make sense
and logically solve the problem/task.
Assignments: The assignment operator is ←. Assignments should be made in the
following format: ←
What are the key characteristics that should be seen in the pseudocode?
• Each instruction is on one line.
• Use capital letters for keywords. Like INPUT, OUPUT, IF, THEN, ELSE, END IF.
• Variables are assigned using the <- operator.
• Pseudocode has no fixed syntax.
• It is written in a list of simple instruction.
Example: Write a pseudocode to add three numbers and find its average.
INPUT Num1
INPUT Num2
INPUT Num3
SumNum1+ Num2+ Num3
OUTPUT Sum
Sequence pseudocode:
• Write Pseudocode that will take two numbers as input, calculates their sum and
displays output.
• Write pseudo code that reads two numbers and multiplies them together and
print out their product.
• Write down Pseudocode that will take marks of physics, chemistry and math as
input, calculates the average and displays output.
• Write Pseudocode to find the area and perimeter of a rectangle and displays the
area and perimeter
Selection Statement:
Definition: If statements are a fundamental building block of computer programming
and are used to make decisions based on conditions. In pseudocode, if statements are
used to control the flow of an algorithm and to specify which actions should be taken
depending on certain conditions.
Comparative operators:
• Comparative operators are used in Pseudocode to compare two values.
• They are also known as relational operators.
• This table shows the comparative operators available in programming.
Operat Descripti
Exampl Resul
or on
e t
Less
< 4<7
than True
Greater
> 4>7 False
than
Lesser or
<= 9 <= 8 False
equal to
>= Greater 5>=3 True
or equal
to
Example: To check the entered age is adult or not
Practice task:
1. Write a pseudocode that asks the user to input their exam score. If the score is
50 or above, the program should display "Congratulations, you passed!" If the
score is below 50, the program should display "Sorry, you failed. Better luck
next time.“
2. Write a pseudocode that prompts the user to enter their driving speed. If the
speed is over 70 mph, display "You are speeding! You may get a ticket." If the
speed is 70 mph or below, display "You are driving within the speed limit."
Combine condition:
Practice Task:
– A theme park give free entry for children below 5 age and senior citizenship.
Input age and check the entered age is eligible for free ticket or not.
– Write pseudocode for a weather system that outputs "Wear a jacket" if the
temperature is below 15°C OR if it is raining.
– Enter the day of the week. If day is Monday or Friday, display a message
“Exercise at Gym”, for all the other days, display a message “Exercise at home”.