You are on page 1of 15

Computer

Science O.L.
(New Syllabus)

“Everybody should learn to program a computer,


because it teaches you how to think.”
- Steve Jobs
Practical

01
Programming pt.4
(Conditional)
Programming pt.3
● Nested IFs

● Ranges

● Tracing

● Code debugging
Standard IF statement
Statement that branches to two different routes
IF [ Weather is cold? ] THEN

ELSE

ENDIF

What if we want further routes?


Nested IFs
It is IF technique that offers infinite routes or possibilities to add in the program.

By covering all cases by adding IF statements inside each other


Nested IFs
IF [ Q1 ?] THEN

ELSE

IF [ Q1 ?] THEN

ELSE

ENDIF

ENDIF
Quick question
Design a program that decide whether apple is good to eat , Cannot be eaten or Mama te3melo
3aseer from health bar that user will enter
In case apple health is more than 80 then “Good to eat”
In case more than 30 but less than 80 “ Mama te3melo 3aseer”
Code: Otherwise “Can’t be eaten”
Quick question
-Design a program, using pseudocode, which inputs from the user weight at the start of the year and the weight at the end of
the year. The program should output whether the user: (Don‘t forget to validate)
-Gained Weight
-Lost Weight
Code: -No change in weight
Quick question
Design a program that inputs a number and prints “Correct range” if the number is between 1 and 20 (inclusive) or between -
1 and -20 (exclusive), otherwise the program outputs “Wrong range”.

Code:
Quick question
Write program to read an integer vale for SCORE and print the appropriate grade on the following Don’t forget to validate

Code:
Quick question
Design a program that reads from the user his/her mark and outputs the grade according to the following grade boundaries:
Don’t forget to validate

Code:
Quick question
Write a pseudocode that inputs the savings of a bank client without interest rate. The program must output the updated amount after applying
interest according to the following criteria:

Code:
Quick question
State the output of the following program if the value stored in Number is 4

IF Number=0 THEN

OUTPUT “Zero" Screen


ELSE
IF Number > 0 THEN

OUTPUT “Positive"

ELSE

OUTPUT “Negative"

ENDIF
ENDIF
Quick question
State the output of the following program if the value stored in Number1 is 4 and the value stored
in Number2 is 5
IF Number1 = Number2 THEN OUTPUT
"Equal"
Screen
ELSE
IF Number1 > Number2 THEN

OUTPUT "The larger number is ", Number1


ELSE

OUTPUT "The larger number is ", Number2

ENDIF
ENDIF
Quick question
The following program should display Valid if the weight is
greater than or equal to 0 and display Invalid otherwise.

01 DECLARE Weight : REAL


02 INPUT Weights
03 IF Weight > 0 THEN
04 OUTPUT "Invalid“
05 ELSE
06 OUTPUT "Valid"
07 ENDIF

You might also like