Professional Documents
Culture Documents
Pseudo Code
Pseudo Code
Pseudo Code
TO
PSEUDOCODE
VARIABLES & CONSTANTS
These occupy a space in
memory that holds data
that a program might use
or manipulate.
VARIABLES
These values can change
throughout the algorithm as data
is processed.
*Processing
*Output
*Processing
*Output
• Relational
Operators
CONDITIONAL STATEMENTS
• Every conditional statement starts
with a logical test.
• Yes/No OR True/False
IF…THEN
Actions to be carried out if TRUE.
IF Logical Test
ENDIF
IF Logical Test
THEN Actions if True
ENDIF
← CONSTANT
← VARIABLE
IF…THEN…ELSE
Actions to be carried out if TRUE
AND
Actions to be carried out if FALSE
IF Logical Test
ENDIF
IF Logical Test
THEN Actions if True
ELSE Actions if False
ENDIF
INPUT age
IF age > 12
THEN OUTPUT “You may buy War Machine”
ELSE OUTPUT “ You may not buy War Machine”
ENDIF
Rakesh wants to buy chocolate. He
has decided that if his allowance is
$10 or more, he will buy chocolate.
If his allowance is less than $10, he
will not buy chocolate. Write this in
pseudocode.
INPUT allowance
IF allowance >= 10
THEN OUTPUT “Buy chocolate”
ELSE OUTPUT “ Do not buy chocolate”
ENDIF
Darryl wants to cool down because
it’s a really hot day. If the
temperature is less than 35
degrees, he will go to the beach,
otherwise he will go to the pool.
Write this in pseudocode.
INPUT temperature
IF temperature < 35
THEN OUTPUT “Go to the beach”
ELSE OUTPUT “Go to the pool”
ENDIF
The year is 2022. Input the year Anita’s
dog Spike was born. Calculate the dog’s
age. If the dog is 8 years or older, he
needs to take special supplements. If he
is younger than 8 years, he needs to get
a booster shot. Write this in pseudocode.
year = 2022
INPUT birth_year
IF Score > 60
IF Score > 60
INPUT pay
OUTPUT tax
ENDFOR
There are 10 students
in a class. Each student
gets marks on an essay
and marks on a test.
Output the total mark
for each student.
FOR students 1 TO 10 DO
test_mark
ENDFOR
There are 15 students
in a class. Input the
score for each
student. Determine
and print the highest
score.
high_score = 0
high_score_student = null
FOR students 1 TO 15 DO
INPUT student_name, score
IF score > high_score
THEN high_score = score
high_score_student = student_name
ENDIF
ENDFOR
PRINT high_score_student, high_score
Enter 10 numbers and
calculate the total.
total = 0
FOR count 1 TO 10 DO
INPUT number
total = total + number
ENDFOR
OUTPUT total
Enter 10 numbers and
find the largest
number.
largest_number = 0
FOR count 1 TO 10 DO
INPUT number
IF number > largest_number
THEN largest_number = number
ENDIF
ENDFOR
OUTPUT largest_number
Find the average
exam mark out of 5
subjects. Print the
answer.
total = 0
count = 0
FOR subjects 1 to 10 DO
INPUT exam_mark
sum = sum + exam_mark
count = count + 1
ENDFOR
average = sum/count
PRINT average
2) CONDITION-CONTROLLED LOOPS
• A condition needs to be met to stop the loop
INPUT password
WHILE password <> ‘Sesame’ DO
OUTPUT ‘Wrong password, try again’
INPUT Password
ENDWHILE
OUTPUT ‘Correct Password’
• Output “What is 40 + 60”
• Input an answer
• If the correct answer is input
say
“Yes, well done and stop
• Otherwise output “No, try again”
and repeat the actions
OUTPUT “What is 40 + 60?”
INPUT Answer
WHILE Answer <> 100 DO
OUTPUT “No, try again”
INPUT Answer
ENDWHILE
OUTPUT “Yes, well done”
Print: Enter a number greater
than 10. Accept an answer. If
the answer is less than 10,
print: enter a number greater
then 10. If the answer is greater
than 10, print: “Well done!”
PRINT “Enter a number greater than 10”
INPUT answer
WHILE answer < 10 DO
PRINT “Enter a number greater then 10”
INPUT answer
ENDWHILE
PRINT “Well done”
REPEAT
Statement
UNTIL Condition is True