Learning objectives
Selection Statements:
Use selection statements, limited to IF, THEN, ELSE, presented as flowcharts.
Predict Outcomes:
7CT.05: Predict the outcome of flowcharts that use selection statements.
Comparison Operators:
7CT.09: Select and use appropriate comparison operators in algorithms, limited to <, >,
<=, >=, == (equal to) and != (not equal to).
TASK 1: Draw flowchart and write python program for the given pseudocode
START
INPUT n
IF n < 1 OR n > 999 THEN
OUTPUT "Input number is out of range"
ELSE
IF n < 10 THEN
digits ← "one-digit"
ELSE IF n < 100 THEN
digits ← "two-digit"
ELSE
digits ← "three-digit"
END IF
IF n MOD 2 = 0 THEN
parity ← "even"
ELSE
parity ← "odd"
END IF
description ← digits & " " & parity & " number"
OUTPUT description
END IF
END
TASK 2. Identify the variables in the pseudocode and specify their data types.
TASK 3: Complete the trace table for the following test case: n = 123.
Trace Table:
Step
N
digits
parity
description
1
123
Output
TASK 4: Write a step-by-step explanation of how the pseudocode processes the input n.
TASK 5: Discuss the operators involved in this program
TASK 6: Complete the first column ‘TERM’ that matches the definition. Use the following words.
Concatenation, ELSE Statement, Modulus, String, Range, Trace Table, START/END, Condition, Output, IF
Statement, Input, Execution, Variable, Integer
Terms Related to Program Logic
Term
Definition
A whole number without a fraction part. Examples: -1, 0, 1, 123, etc.
The set of values that a variable can take. In this case, the range is from 1 to 999 inclusive.
An expression that evaluates to either true or false. Used in decision-making (e.g., n < 1 OR n >
999).
The operation that finds the remainder after division of one number by another. Symbolized by
MOD.
The operation of joining two or more strings end-to-end. Represented by & in pseudocode.
Terms Related to Data Types
Term
Definition
A sequence of characters. In this program, "one-digit", "two-digit", "three-digit", "even", and "odd"
are string values.
A symbolic name associated with a value that may change during the execution of a program.
Examples: n, digits, parity, and description in the program.
The information produced by the program and sent to the user. In this case, it could be the
description of the number or an error message.
Terms Related to Program Execution
Term
Definition
The data given to a program by the user or another system. Here, it is the integer n that the user
provides.
The process of carrying out the instructions in a program.
A table that shows the values of variables at each step in the execution of a program.
Terms Related to Control Structures
Term
Definition
A control structure that allows for conditional execution of code segments. In this program, it
determines the range check and assigns values based on conditions.
A control structure that specifies an alternative action if the condition in an IF statement is false.
Keywords used to indicate the start and end of a pseudocode block, respectively.