Analysis

The first stage: figuring out what the software must do.

1. Functional Requirements

Inputs, Processes, and Outputs (IPO).

  • Input: Ask for length and breadth.
  • Process: Calculate area = length * breadth.
  • Output: Display "Area is 50".
2. End-User Requirements

What the users need/want (Usability & Constraints).

  • Must be easy to read (clear font).
  • Must load quickly (under 2s).
  • Must run on school tablets.
  • Must handle errors without crashing.

Design Notations

1. Pseudocode
1. Receive length from user
2. Receive breadth from user
3. Set area to length * breadth
4. Display area
2. Structure Diagram
Main Program
Input
Process
Output
3. Flowchart Symbols
Start/Stop
In/Out
Process
Decision

Data Types

What is a Variable?

A named storage location in memory holding a value that can change while the program runs.

Assignment

Giving a variable a value using the = symbol.

score = 10 # Assigns 10 to 'score'
Type Description Example
Integer Whole number 10, -5
Real (Float) Decimal number 3.14, 0.5
String Text characters "Hello"
Char Single character 'A', '!'
Boolean True or False True
1D Arrays (Lists)

Storing multiple items under one name.

scores = [10, 20, 55]
print(scores[0]) # Prints 10

Maths & Logic

Arithmetic & Comparators
+ Add
- Sub
* Mult
/ Div
== Eq
!= Not
> Big
< Small
Booleans & Logic

Comparisons return a Boolean value: True or False.

Op Meaning Example (x=5)
and Both must be True x>0 and x<10 (True)
or One must be True x==5 or x==0 (True)
not Reverses True/False not(x==5) (False)
String Concatenation
age = 15
# Use str() to join numbers
print("Age: " + str(age))

Constructs

Selection (Decisions)
1. Simple If (1 Path)
if lives == 0:
  print("Game Over")
2. If...Else (2 Paths)
if age >= 18:
  print("Adult")
else:
  print("Child")
3. Elif (Many Paths)
if temp > 30:
  print("Hot")
elif temp > 15:
  print("Warm")
else: # Catch-all (Required)
  print("Cold")
Fixed Loop (For)

Used when you know how many times to loop.

for i in range(10):
  print(i)
Conditional Loop (While)

Loops until a condition is met.

while password != "123":
  password = input(...)

Pre-defined Functions

Function Purpose
input() Get text from user
print() Display text
int() Convert to Integer
float() Convert to Real
str() Convert to String
len() Length of string/list
round(x, 2) Round to 2 decimal places
random.randint() Generate random number
Requires: import random

Input Validation

Design: Get Input → While Invalid → Error & Retry → End Loop.
1. Range Check (Numbers)
score = int(input("Enter (0-100): "))
while score < 0 or score > 100:
  print("Error!")
  score = int(input("Try again: "))
2. Length Check (String)
pw = input("Password (min 8): ")
while len(pw) < 8:
  print("Too short!")
  pw = input("Try again: ")
3. Restricted Choice (List)
opt = input("A, B or C: ").upper()
while opt not in ["A", "B", "C"]:
  print("Invalid!")
  opt = input("A, B or C: ").upper()

Running Total

Adds up a series of numbers. Uses a Fixed Loop.

Design:
  1. Set total to 0.
  2. Loop X times.
  3. Get number.
  4. Add number to total.
  5. Display total (after loop).
total = 0

for i in range(5):
  num = int(input("Number? "))
  total = total + num

print("Final Total:", total)

Traversing Array

Visiting every item in a list (e.g., for Linear Search or Counting).

Design:
  1. Set up list.
  2. Loop through list items.
  3. Check/Process current item.
names = ["Ada", "Bob", "Cat"]
target = "Bob"
found = False

for person in names:
  if person == target:
    found = True
    print("Found him!")

Test Data

Example: A program accepts numbers 1 to 100.

1. Normal Data within the range.
e.g., 5, 20, 50, 99
2. Extreme (Boundary) Data on the exact edge of the limits.
e.g., 1 and 100
3. Exceptional Data that should not be accepted (Invalid).
e.g., 0, 101, -5, "Ten"

Error Types

1. Syntax Error

Grammar mistakes. The code won't even start.

print("Hello" <- Missing )
SyntaxError: unexpected EOF while parsing
if x = 10: <- Need ==
SyntaxError: invalid syntax
2. Execution Error

Crashes *while* running (Runtime error).

num = 5 / 0 <- Impossible
ZeroDivisionError: division by zero
print(score) <- Not created yet
NameError: name 'score' is not defined
3. Logic Error

Runs without crashing, but gives the wrong result.

area = length + breadth
Result: 20 (Expected 100)
avg = a + b / 2 <- BODMAS!
Calculates b/2 then adds a. Needs (a+b)/2

Evaluation

Checking the quality of the final solution.

  • Fitness for Purpose

    Does it meet the functional requirements?

    e.g. Program successfully calculates the average mark.
  • Robustness

    Can it cope with errors without crashing?

    e.g. Using a While loop to validate input range.
  • Readability

    Is it easy for a human to read?

    e.g. Using meaningful variable names (total_score) and internal comments (# calc avg).
  • Efficiency

    Does it use resources (CPU/RAM) well?

    e.g. Using a Loop instead of writing the same code 5 times.

1. Analysis

Scenario:

A program is needed to store 5 marks for a student, calculate the average, and determine if they pass.

Functional Requirements (IPO)
  • Input: Student Name, 5 Marks (0-100).
  • Process: Calculate total, Calculate average, Determine Pass/Fail (>=50).
  • Output: Name, Average, Pass/Fail message.
End-User Requirements
  • The program must be easy to read.
  • It must validate inputs to ensure no invalid marks (e.g., -5 or 150) crash the system.

2. Design (Pseudocode)

1. SET total TO 0
2. RECEIVE student_name FROM KEYBOARD
3. FOR loop FROM 1 TO 5
4.   RECEIVE mark FROM KEYBOARD
5.   WHILE mark < 0 OR mark > 100
6.     DISPLAY "Invalid Mark"
7.     RECEIVE mark FROM KEYBOARD
8.   END WHILE
9.   ADD mark TO total
10. END FOR
11. SET average TO total / 5
12. DISPLAY student_name AND average
13. IF average >= 50 THEN
14.   DISPLAY "PASS"
15. ELSE
16.   DISPLAY "FAIL"
17. END IF

3. User Interface

Visualising the input/output flow.

Enter student name: Alice
Enter mark 1: 45
Enter mark 2: 105
Invalid! Range is 0-100.
Try again: 95
...
--- Results for Alice ---
Average Mark: 72.0
Result: PASS

4. Implementation (Code)

# Setup Variables
total = 0

# Get Input
student_name = input("Enter student name: ")

# Loop for 5 marks
for i in range(5):
  score = int(input("Enter mark: "))

  # Validation using Logical OR
  while score < 0 or score > 100:
    print("Invalid! Range is 0-100.")
    score = int(input("Try again: "))

  # Running Total
  total = total + score

# Process Average
average = total / 5
average = round(average, 2)

# Output & Decision using Logical AND
print("--- Results for " + student_name + " ---")
print("Average Mark: " + str(average))

if average >= 70:
  print("Result: DISTINCTION")
elif average >= 50 and average < 70:
  print("Result: PASS")
else:
  print("Result: FAIL")

5. Testing

Type Input Expected
Normal 50 Accepted
Extreme 0, 100 Accepted
Exceptional -1, 101 Error Msg

6. Evaluation

Fitness for Purpose

Does it meet the Functional Requirements?

Yes, it successfully calculates the average and outputs Pass/Fail correctly.
Robustness

Can it handle errors/invalid data?

Yes, the while loop catches marks <0 or >100 so the program doesn't crash or give bad results.
Readability

Is the code easy for a human to understand?

Yes, uses meaningful names (e.g., student_name, total) and internal comments (# Calculate Average).
Efficiency

Does it use resources well?

Yes, using a For Loop reduces lines of code (vs writing input code 5 times). Using an Array is better than 5 separate variables.