Code Guide: Input, Output And Variable Assignment Programs (Copy)
Input, Output And Variable Assignment Programs
Core Rules (Must Follow In Every Program)
- INPUT reads data into a variable
- Assignment stores/calculates a value into a variable using
← - OUTPUT displays a value/message
- A variable must be:
- Declared (when required by the question style)
- Assigned before being used in calculations or OUTPUT
- Use meaningful identifiers (examiner-friendly)
- Good:
totalMarks,age,discountRate - Weak:
a,b,x(only acceptable in tiny algorithms)
- Good:
Variable Declaration (Common Data Types)
Declaration Format
DECLARE variableName : DATA_TYPE
Common AS-Level Data Types
| Data Type | Used For | Example Values |
|---|---|---|
| INTEGER | Whole numbers | 5, -12, 100 |
| REAL | Decimal numbers | 3.5, 0.25, -1.8 |
| STRING | Text | “Ali”, “A1B2” |
| CHAR | Single character | “A”, “7” |
| BOOLEAN | True/False | TRUE, FALSE |
| DATE | Date values | (depends on given format) |
Example Declarations
DECLARE age : INTEGER
DECLARE price : REAL
DECLARE name : STRING
DECLARE grade : CHAR
DECLARE valid : BOOLEAN
Variable Assignment (The ← Operator)
Basic Assignment
age ← 18
name ← "Hamza"
valid ← TRUE
Assignment Using Expressions
- Arithmetic
total ← num1 + num2
area ← length * width
average ← total / count
- Using brackets to control order
result ← (a + b) * c
Common Mistakes To Avoid
- Using a variable before assigning it
- Wrong:
total ← total + num
- Correct:
total ← 0total ← total + num
- Wrong:
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions and 11 World Records For Educate A Change AS Level Computer Science Full Scale Course
INPUT Statements (Correct Patterns)
Single Input
INPUT age
Multiple Inputs (Separate Lines)
INPUT num1
INPUT num2
Input Into Arrays (If Needed)
FOR i ← 1 TO n
INPUT marks[i]
NEXT i
Input Validation (Only If The Task Requires It)
- Range validation using REPEAT UNTIL (cleanest)
REPEAT
INPUT mark
UNTIL mark >= 0 AND mark <= 100
OUTPUT Statements (Correct Patterns)
Output A Variable
OUTPUT total
Output A Message
OUTPUT "Welcome"
Output Message + Variable (Exam-Safe Ways)
- Method 1: Separate outputs (safest and always accepted)
OUTPUT "Total is:"
OUTPUT total
- Method 2: Same line style (only if your accepted pseudocode format supports it)
OUTPUT "Total is ", total
Output Multiple Values Clearly
OUTPUT "Max:"
OUTPUT max
OUTPUT "Min:"
OUTPUT min
Building Small Programs (Input → Process → Output)
Program 1: Input A Name And Output Greeting
DECLARE name : STRING
INPUT name
OUTPUT "Hello"
OUTPUT name
Program 2: Input Two Integers And Output Their Sum
DECLARE num1 : INTEGER
DECLARE num2 : INTEGER
DECLARE sum : INTEGER
INPUT num1
INPUT num2
sum ← num1 + num2
OUTPUT sum
Program 3: Input Length And Width And Output Area
DECLARE length : REAL
DECLARE width : REAL
DECLARE area : REAL
INPUT length
INPUT width
area ← length * width
OUTPUT area
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions and 11 World Records For Educate A Change AS Level Computer Science Full Scale Course
Assignment Patterns Students Must Memorise
Accumulator Pattern (Running Total)
- Used for totals, sums, money, marks
total ← 0
total ← total + value
Counter Pattern (Counting Occurrences)
- Used for “how many…”
count ← 0
count ← count + 1
Swap Pattern (When Two Values Need Exchanging)
temp ← a
a ← b
b ← temp
Operator Quick Sheet (Used In Assignments)
Arithmetic Operators
| Operation | Operator | Example |
|---|---|---|
| Add | + | sum ← a + b |
| Subtract | – | diff ← a - b |
| Multiply | * | area ← l * w |
| Divide | / | avg ← total / n |
| MOD (remainder) | MOD | IF num MOD 2 = 0 THEN |
Comparison Operators
| Meaning | Operator | Example |
|---|---|---|
| Equal | = | IF x = 5 THEN |
| Not equal | <> | IF choice <> "Q" THEN |
| Greater | > | IF score > 70 THEN |
| Less | < | IF temp < 0 THEN |
| Greater or equal | >= | IF mark >= 50 THEN |
| Less or equal | <= | IF age <= 18 THEN |
Boolean Operators
| Meaning | Operator | Example |
|---|---|---|
| AND | AND | IF x >= 1 AND x <= 10 THEN |
| OR | OR | IF opt = 1 OR opt = 2 THEN |
| NOT | NOT | IF NOT valid THEN |
Common Exam Mini-Tasks (With Perfect Templates)
Task A: Input 3 Numbers And Output Their Average
DECLARE a : REAL
DECLARE b : REAL
DECLARE c : REAL
DECLARE average : REAL
INPUT a
INPUT b
INPUT c
average ← (a + b + c) / 3
OUTPUT average
Task B: Input Price And Output Price After 10% Discount
DECLARE price : REAL
DECLARE finalPrice : REAL
INPUT price
finalPrice ← price - (price * 0.10)
OUTPUT finalPrice
Task C: Input Temperature In Celsius And Output Fahrenheit
- Formula:
F = (C * 9 / 5) + 32
DECLARE c : REAL
DECLARE f : REAL
INPUT c
f ← (c * 9 / 5) + 32
OUTPUT f
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions and 11 World Records For Educate A Change AS Level Computer Science Full Scale Course
Debug-Proofing Input/Output/Assignment Questions (Mark-Saving Checks)
Check 1: Have You Initialised What Needs Initialising?
- Accumulators must start at 0
- Counters must start at 0
- Flags must start at FALSE
- Max/Min must start from first input when required
Check 2: Does Every Variable Used In An Expression Have A Value?
- Wrong:
area ← length * width(but width not input)
- Correct:
- Input all required values first
Check 3: Is OUTPUT Showing The Required Value (Not The Wrong Variable)?
- Common slip:
- Calculating
sumbut outputtingnum1
- Calculating
Check 4: Are Brackets Used Where Needed?
- Wrong:
average ← a + b + c / 3
- Correct:
average ← (a + b + c) / 3
Common Mistakes And Their Fixes
Mistake 1: Using = Like Assignment (Wrong Mental Model)
- Correct assignment is always
← - Correct comparison in IF is
= - Example:
- Assignment:
x ← 10
- Comparison:
IF x = 10 THEN
- Assignment:
Mistake 2: Missing One INPUT Line
- Fix approach
- Write a mini checklist:
- “How many inputs are required?”
- Write a mini checklist:
Mistake 3: Outputting Inside A Loop By Accident
- If the question asks for final output only:
- Output after the loop, not inside
Mistake 4: Mixing INTEGER And REAL Carelessly
- If division is involved:
- Use REAL for average and totals when needed
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions and 11 World Records For Educate A Change AS Level Computer Science Full Scale Course
Quick Copy-Paste Templates (Fast Revision)
Template 1: Simple IPO Program
INPUT value
result ← PROCESS(value)
OUTPUT result
Template 2: Two Inputs → One Output
INPUT a
INPUT b
result ← a + b
OUTPUT result
Template 3: Validation Then Use
REPEAT
INPUT value
UNTIL value >= min AND value <= max
OUTPUT value
Template 4: Output Label + Value Safely
OUTPUT "Answer:"
OUTPUT result
