GCSE Revision Aid: This resource is designed to support your revision and may contain errors. If you find a discrepancy with your class teaching, your teacher is correct — please let us know at gcserevise@scott.scottrix.co.uk.

CS11: Input, Output & String Handling

Foundation Higher AQAEdexcelOCREduqasCCEA

Mastering INPUT and OUTPUT commands, string operations (LENGTH, POSITION, SUBSTRING), concatenation, character codes, and type conversion.

Fastmail

📥 INPUT Command

INPUT gets data from the user (or another source) and stores it in a variable. In most pseudo-code, INPUT returns a string, so you may need to convert it to the correct data type.
INPUT Examples
INPUT name                         // Get a string
INPUT "Enter your age: ", age      // With prompt
age ← INT(INPUT("Enter age: "))  // Get and convert to integer
Important: Data received via INPUT is usually a string. If you need to perform arithmetic, you must convert it using INT(), FLOAT(), or other type conversion functions.

📤 OUTPUT Command

OUTPUT displays data to the user. You can output variables, strings, numbers, and expressions. Use & to concatenate (join) items in the output.
OUTPUT Examples
OUTPUT "Hello, World!"                    // Simple string
OUTPUT score                              // Variable value
OUTPUT "Your score is " & STR(score)      // Combined string and variable
OUTPUT "Total: ", total, " Average: ", avg  // Multiple items
Formatted Output
name ← "Alice"
score ← 95
OUTPUT "Name: " & name & " | Score: " & STR(score)
// Output: Name: Alice | Score: 95

📝 String Operations

String operations allow you to manipulate text data. At GCSE, you need to know LENGTH, POSITION (or INSTR), SUBSTRING, and concatenation.

LENGTH

LENGTH Function
word ← "Computer"
OUTPUT LENGTH(word)    // 8
OUTPUT LENGTH("Hi")    // 2
OUTPUT LENGTH("")      // 0 (empty string)

POSITION (or INSTR)

POSITION Function
text ← "Hello World"
OUTPUT POSITION(text, "World")    // 6 (found at position 6)
OUTPUT POSITION(text, "xyz")      // -1 (not found)
OUTPUT POSITION(text, "o")        // 5 (first occurrence)
Note: POSITION returns the index of the first character of the found substring. If the substring is not found, it returns -1. Positions are zero-indexed in many specifications.

SUBSTRING

SUBSTRING Function
text ← "Computer Science"
OUTPUT SUBSTRING(text, 0, 3)     // "Com" (from position 0, 3 characters)
OUTPUT SUBSTRING(text, 9, 7)     // "Science" (from position 9, 7 characters)
OUTPUT SUBSTRING(text, 3, 3)     // "put"
SUBSTRING(string, start, length):
start = the index where the substring begins (0-indexed)
length = how many characters to extract

"Computer"[0:3] means characters at positions 0, 1, 2 = "Com"

Concatenation

String Concatenation
firstName ← "Alice"
lastName ← "Smith"
fullName ← firstName & " " & lastName
OUTPUT fullName    // "Alice Smith"

🔤 Character-Code Conversion

Every character is stored in a computer as a numeric code (ASCII or Unicode). The ASC() function converts a character to its code, and CHR() converts a code back to a character.
Function Purpose Example Result
ASC(character) Returns the character code of a single character ASC('A') 65
CHR(code) Returns the character for a given code CHR(65) 'A'

Key ASCII Codes to Remember

CharacterASCII Code
'A'65
'Z'90
'a'97
'z'122
'0'48
'9'57
' '32
Useful ASCII Facts:
Uppercase letters: 65 (A) to 90 (Z)
Lowercase letters: 97 (a) to 122 (z)
Digits: 48 (0) to 57 (9)
Difference between 'a' and 'A': 97 - 65 = 32
To convert uppercase to lowercase: CHR(ASC(char) + 32)
Converting Uppercase to Lowercase
letter ← 'G'
lower ← CHR(ASC(letter) + 32)
OUTPUT lower    // 'g'
Checking if a Character is a Digit
INPUT char
IF ASC(char) >= 48 AND ASC(char) <= 57 THEN
    OUTPUT char, " is a digit"
ELSE
    OUTPUT char, " is not a digit"
ENDIF

🔄 Type Conversion Functions

Type conversion functions change data from one type to another. These are essential when working with user input (which arrives as a string) or when formatting output.
Function Converts To Example Result
INT(value) Integer INT("42") 42
INT(value) Integer (truncates) INT(3.99) 3
FLOAT(value) Real / Float FLOAT("3.14") 3.14
STR(value) String STR(42) "42"
Complete Input/Output Example
INPUT "Enter first number: ", input1
INPUT "Enter second number: ", input2
num1 ← FLOAT(input1)
num2 ← FLOAT(input2)
total ← num1 + num2
OUTPUT "The sum of " & input1 & " and " & input2 & " is " & STR(total)

⚠️ Common Mistakes

Mistake Why It's Wrong How to Fix It
Not converting INPUT to number "5" + "3" = "53" not 8 Use INT() or FLOAT() before arithmetic
SUBSTRING wrong parameters Confusing start position with end position SUBSTRING(string, start, length) - start + length
POSITION returning -1 Forgetting to handle "not found" case Check if result = -1 before using it
ASC() on a string ASC() takes a single character, not a string Use ASC(SUBSTRING(text, 0, 1)) for first char
Forgetting STR() in output Cannot concatenate string with number directly Convert number to string with STR() first

❓ Practice Questions

Q1: What does LENGTH("GCSE Computer Science") return?

Q2: Write pseudo-code that asks for a word and outputs the first three characters.

Q3: What is the ASCII code for 'A'? What is CHR(97)?

Q4: Write pseudo-code that takes two numbers as input, adds them, and outputs the result as a sentence.

Q5: Write pseudo-code that checks if the first character of a word is uppercase.

✅ Answers

  1. 20 characters (including the space).
  2. INPUT word
    OUTPUT SUBSTRING(word, 0, 3)
  3. The ASCII code for 'A' is 65. CHR(97) = 'a'.
  4. INPUT "Enter first number: ", a
    INPUT "Enter second number: ", b
    num1 ← FLOAT(a)
    num2 ← FLOAT(b)
    total ← num1 + num2
    OUTPUT a & " + " & b & " = " & STR(total)
  5. INPUT word
    firstChar ← SUBSTRING(word, 0, 1)
    IF ASC(firstChar) >= 65 AND ASC(firstChar) <= 90 THEN
        OUTPUT "First character is uppercase"
    ELSE
        OUTPUT "First character is not uppercase"
    ENDIF

🎯 Exam Tips

⚠️ Common Errors

✗ Forgetting to cast input from string to the correct data type ✓ INPUT usually returns a string; you must convert it to INTEGER or REAL before arithmetic, e.g. age ← INTEGER(INPUT('Age: ')).

✗ Thinking string indexing starts at 1 in all languages ✓ Python and most languages use 0-based indexing; the first character is at index 0. Always check the convention for your exam board.

✗ Confusing LENGTH() and SUBSTRING() functions ✓ LENGTH() returns the number of characters in a string; SUBSTRING(string, start, length) extracts a portion of the string.

✗ Not realising that string concatenation does not add spaces automatically ✓ Joining 'Hello' & 'World' gives 'HelloWorld'. You must explicitly include a space: 'Hello' & ' ' & 'World' gives 'Hello World'.

✍️ Model Answer

Full-Mark Response

Write pseudo-code that inputs a full name (e.g. 'Jane Smith'), extracts and outputs the first name and last name separately, then outputs the initials in uppercase. [5 marks]

INPUT 'Enter full name: ', fullname space_pos ← 0 FOR i ← 0 TO LENGTH(fullname) - 1 IF fullname[i] = ' ' THEN space_pos ← i ENDIF NEXT i firstname ← SUBSTRING(fullname, 0, space_pos) lastname ← SUBSTRING(fullname, space_pos + 1, LENGTH(fullname) - space_pos - 1) OUTPUT 'First name: ' & firstname OUTPUT 'Last name: ' & lastname initials ← UPPER(firstname[0]) & '.' & UPPER(lastname[0]) & '.' OUTPUT 'Initials: ' & initials

📊 AO Deep Dive

Assessment Objective Analysis

AO1 (Computational Thinking — 40%): Demonstrate knowledge and understanding of the principles and concepts of computer science, including input, output and string handling functions for AQA 8525, OCR J277 & Edexcel 1CP2.

AO2 (Application — 40%): Apply knowledge and understanding of computer science, including input, output and string handling functions to analyse problems in computational terms and to design, write and evaluate solutions.

AO3 (Evaluation — 20%): Evaluate the effectiveness, correctness and efficiency of computational solutions, including input, output and string handling functions, and make reasoned judgements about trade-offs.

📝 Exam Technique

GCSE Computer Science Exam Tips:
Know key string functions: LENGTH(), SUBSTRING(), UPPER(), LOWER(), LEFT(), RIGHT(), ASC(), CHR(). Always cast input to the correct type before processing. Remember string indexing convention for your exam board. For string manipulation, find the space position first to split names. Show each step clearly when extracting substrings.

📝 Exam Questions by Topic

🎬 Video Resources

Share this page

Ready to ace your GCSE Computer Science exams?

Get the best revision books and guides to boost your grades.