Computer science programming

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/82

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 6:50 AM on 5/17/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

83 Terms

1
New cards

What is a variable?

A named memory location that stores a value that can change during program execution — declared by giving it a name and assigning a value — eg x = 5

2
New cards

What is a constant?

A named memory location that stores a value that cannot change during program execution — declared using const — eg const pi = 3.14

3
New cards

Why use constants instead of variables?

Makes code easier to read and maintain — prevents accidental changes to important values — if the value needs updating you only change it in one place

4
New cards

What is an assignment?

Giving a value to a variable or constant using the = operator — eg name = "Sam" or score = 0

5
New cards

What is the difference between a variable and a constant?

A variable can change its value during the program — a constant cannot change once declared

6
New cards

What is sequence in programming?

Statements are executed one after another in the order they are written — the simplest and most fundamental programming construct

7
New cards

What is selection in programming?

The program chooses between different paths based on a condition being true or false — implemented using IF THEN ELSE or SWITCH CASE statements

8
New cards

What is iteration in programming?

Repeating a block of code — can be count-controlled using a FOR loop — or condition-controlled using WHILE or DO UNTIL loops

9
New cards

What is a count-controlled loop?

A loop that repeats a fixed known number of times — uses a FOR loop — the number of repetitions is determined before the loop starts

10
New cards

What is a condition-controlled loop?

A loop that repeats based on whether a condition is true or false — the number of repetitions is not known in advance — uses WHILE or DO UNTIL

11
New cards

What is the difference between a WHILE loop and a DO UNTIL loop?

WHILE — checks the condition before entering the loop — may never execute if condition is immediately false. DO UNTIL — checks the condition after the loop body — always executes at least once regardless of the condition

12
New cards

Write a FOR loop in OCR ERL that prints the numbers 1 to 10

for i=1 to 10. print(i). next i

13
New cards

Write a FOR loop in OCR ERL that prints even numbers from 2 to 10

for i=2 to 10 step 2. print(i). next i

14
New cards

Write a FOR loop in OCR ERL that counts down from 10 to 1

for i=10 to 1 step -1. print(i). next i

15
New cards

Write a WHILE loop in OCR ERL that keeps asking for a password until the user enters "letmein"

password = input("Enter password"). while password != "letmein". password = input("Enter password"). endwhile

16
New cards

Write a DO UNTIL loop in OCR ERL that keeps asking for a number until the user enters a number greater than 10

do. num = int(input("Enter a number")). until num > 10

17
New cards

What are the comparison operators in OCR ERL and what do they mean?

== equal to. != not equal to. < less than.

18
New cards

What are the arithmetic operators in OCR ERL?

  • addition. - subtraction. * multiplication. / division. ^ exponentiation (to the power). MOD modulo (remainder after division). DIV quotient (whole number result of division)
19
New cards

What does MOD do and give an example?

Returns the remainder after division — 10 MOD 3 = 1 because 10 divided by 3 is 3 remainder 1 — useful for checking if a number is even or odd

20
New cards

What does DIV do and give an example?

Returns the whole number quotient after division ignoring the remainder — 10 DIV 3 = 3 because 3 goes into 10 three times — useful when you need integer division

21
New cards

What does ^ do and give an example?

Raises a number to a power — 2^3 = 8 because 2 to the power of 3 is 2×2×2 = 8

22
New cards

What are the Boolean operators AND OR and NOT?

AND — both conditions must be true for the overall result to be true. OR — at least one condition must be true. NOT — reverses the Boolean value — NOT true = false

23
New cards

Write an IF statement in OCR ERL that prints "pass" if score >= 50 and "fail" otherwise

if score >= 50 then. print("pass"). else. print("fail"). endif

24
New cards

Write an IF ELSEIF ELSE statement in OCR ERL that grades a score

if score >= 70 then. print("Distinction"). elseif score >= 50 then. print("Pass"). else. print("Fail"). endif

25
New cards

Write a SWITCH CASE statement in OCR ERL for days of the week

switch day :. case "Mon": print("Monday"). case "Tue": print("Tuesday"). default: print("Other day"). endswitch

26
New cards

When would you use SWITCH CASE instead of IF ELSEIF?

When checking a single variable against many possible specific values — SWITCH CASE is cleaner and easier to read than many ELSEIF statements

27
New cards

What is nesting and give an example?

Placing one construct inside another — eg an IF statement inside a FOR loop — for i=1 to 10. if i MOD 2 == 0 then. print(i). endif. next i — this prints even numbers from 1 to 10

28
New cards

Write a nested loop in OCR ERL that prints a 3x3 grid of asterisks

for row=1 to 3. for col=1 to 3. print("*"). next col. next row

29
New cards

What is an integer data type?

Stores whole numbers with no decimal point — eg 5 — 42 — -7 — used for counting discrete items like scores or ages

30
New cards

What is a real data type?

Stores numbers with a decimal point — eg 3.14 — 2.5 — -0.7 — used when precision beyond whole numbers is needed like prices or measurements

31
New cards

What is a Boolean data type?

Can only hold one of two values — True or False — used in conditions and logical operations

32
New cards

What is a character data type?

Stores a single character — eg 'A' — '3' — '!' — enclosed in single quotes

33
New cards

What is a string data type?

Stores a sequence of characters — eg "Hello" — "Computer Science" — enclosed in double quotes — strings can be manipulated using string operations

34
New cards

What is casting?

Temporarily converting a value from one data type to another — useful when combining different data types or performing operations that require a specific type

35
New cards

Give examples of casting functions in OCR ERL

str(345) — converts integer to string. int("3") — converts string to integer. float("4.52") or real("4.52") — converts string to real. bool("True") — converts string to Boolean

36
New cards

Why would you need to cast user input to an integer?

User input is always received as a string — if you want to perform arithmetic on the input you must cast it to an integer first — eg int(input("Enter a number"))

37
New cards

What happens if you try to add a string and an integer without casting?

A type error occurs — the program crashes because you cannot perform arithmetic between incompatible data types

38
New cards

Choose an appropriate data type for storing a person's age

Integer — age is a whole number

39
New cards

Choose an appropriate data type for storing a person's name

String — a name is a sequence of characters

40
New cards

Choose an appropriate data type for storing whether a user is logged in

Boolean — the answer is either True or False

41
New cards

Choose an appropriate data type for storing a product price

Real — prices include decimal values

42
New cards

Choose an appropriate data type for storing a student's grade letter

Character — a single letter like A B or C

43
New cards

2.2 ADDITIONAL PROGRAMMING TECHNIQUES

44
New cards

What is string concatenation?

Joining two or more strings together using the + operator — eg "Hello" + " " + "World" gives "Hello World"

45
New cards

Write OCR ERL code that asks for a first name and last name and prints the full name

firstName = input("First name"). lastName = input("Last name"). print(firstName + " " + lastName)

46
New cards

What does .length do in OCR ERL?

Returns the number of characters in a string — eg subject = "ComputerScience". subject.length returns 15

47
New cards

What does .substring(x,i) do in OCR ERL?

Returns a substring starting at index x with i characters — 0 indexed — eg "ComputerScience".substring(3,5) returns "puter"

48
New cards

What does .left(i) do in OCR ERL?

Returns the first i characters from the left of a string — eg "ComputerScience".left(4) returns "Comp"

49
New cards

What does .right(i) do in OCR ERL?

Returns the last i characters from the right of a string — eg "ComputerScience".right(3) returns "nce"

50
New cards

What does .upper do in OCR ERL?

Converts all characters in a string to uppercase — eg "hello".upper returns "HELLO"

51
New cards

What does .lower do in OCR ERL?

Converts all characters in a string to lowercase — eg "HELLO".lower returns "hello"

52
New cards

What does ASC() do and give an example?

Returns the ASCII numerical value of a character — eg ASC('A') returns 65 — ASC('B') returns 66

53
New cards

What does CHR() do and give an example?

Returns the character corresponding to an ASCII value — eg CHR(65) returns 'A' — CHR(97) returns 'a'

54
New cards

What is a 1D array?

A fixed length list of elements all of the same data type — accessed using a single index — 0 indexed in OCR ERL — like a single row of boxes each with a numbered position

55
New cards

Declare a 1D array called scores with 6 elements in OCR ERL

array scores[6]

56
New cards

Declare a 1D array in OCR ERL with values already assigned

array colours = ["Blue","Pink","Green","Yellow","Red"]

57
New cards

How do you access the third element of an array called names in OCR ERL?

names[2] — because arrays are 0 indexed so the third element is at index 2

58
New cards

How do you assign a value to the first element of an array called scores?

scores[0] = 100

59
New cards

What is a 2D array?

An array with rows and columns — like a grid or table — accessed using two indices — eg gameboard[row,col] — useful for representing grids boards or database tables

60
New cards

Declare a 2D array called gameboard with 8 rows and 8 columns in OCR ERL

array gameboard[8,8]

61
New cards

Assign the value "Pawn" to row 1 column 0 of a 2D array called gameboard

gameboard[1,0] = "Pawn"

62
New cards

Write OCR ERL code to print all elements of a 1D array called scores with 5 elements

for i=0 to 4. print(scores[i]). next i

63
New cards

What are the file handling operations in OCR ERL?

open() — opens a file. .close() — closes a file. .readLine() — reads the next line. .writeLine(text) — writes a line to end of file. .endOfFile() — returns true if end of file reached. newFile() — creates a new file

64
New cards

Write OCR ERL code to open a file read every line and print it

myFile = open("data.txt"). while NOT myFile.endOfFile(). print(myFile.readLine()). endwhile. myFile.close()

65
New cards

Write OCR ERL code to open a file and write a line to it

myFile = open("data.txt"). myFile.writeLine("New line of text"). myFile.close()

66
New cards

What is a record in programming?

A data structure that stores a collection of related fields which can be different data types — similar to a row in a database table — used to represent real-world entities

67
New cards

What is SQL used for in programming?

Structured Query Language — used to search for and retrieve data from a database — can filter and select specific records

68
New cards

What are the three SQL commands you need to know?

SELECT — specifies which fields to retrieve. FROM — specifies which table to retrieve from. WHERE — filters records based on a condition

69
New cards

Write a SQL query to select all students from a table called Students where grade equals "A"

SELECT * FROM Students WHERE grade == "A"

70
New cards

Write a SQL query to select just the name field from a table called Customers where age is greater than 18

SELECT name FROM Customers WHERE age > 18

71
New cards

What is a procedure in programming?

A named block of code that performs a specific task — can accept parameters — does not return a value — called by its name

72
New cards

Write a procedure in OCR ERL that prints a greeting with a name parameter

procedure greet(name). print("Hello " + name). endprocedure

73
New cards

How do you call a procedure in OCR ERL?

greet("Sam") — write the procedure name followed by any parameters in brackets

74
New cards

What is a function in programming?

A named block of code that performs a task and returns a value — can accept parameters — the returned value can be stored or used directly

75
New cards

Write a function in OCR ERL that squares a number and returns the result

function squared(number). squared = number^2. return squared. endfunction

76
New cards

How do you call a function in OCR ERL and use its return value?

result = squared(4) — stores the returned value in a variable. Or print(squared(4)) — uses the returned value directly

77
New cards

What is the difference between a procedure and a function?

A procedure performs a task but does not return a value. A function performs a task and returns a value that can be used elsewhere in the program

78
New cards

What is a local variable?

A variable declared inside a subprogram — only accessible within that subprogram — cannot be used outside it — destroyed when the subprogram ends

79
New cards

What is a global variable?

A variable declared outside all subprograms — accessible from anywhere in the program — declared using the global keyword in OCR ERL

80
New cards

When should you use local variables instead of global variables?

Local variables are preferred — they prevent accidental changes from other parts of the program — make code easier to debug and maintain — global variables should only be used when the variable genuinely needs to be accessed throughout the entire program

81
New cards

How do you generate a random integer between 1 and 6 in OCR ERL?

myVariable = random(1,6)

82
New cards

How do you generate a random real number between 0.0 and 1.0 in OCR ERL?

myVariable = random(0.0,1.0)

83
New cards

Write OCR ERL code that simulates rolling a dice and prints the result

result = random(1,6). print("You rolled: " + str(result))