Revisionโ€บOCR GCSEโ€บProgramming Fundamentals
OCR GCSE J277 ยท Topic 2.2

Programming Fundamentals

60 practice questions

Practice Questions

60 questions

What data type would you use to store the value True or False?

easy

What is a string?

easy

Explain what casting means and give an example.

medium

What is a constant? How is it different from a variable?

easy

Explain the purpose of comments in code.

easy

Which data type would be most appropriate for storing the number of students in a class?

easy

Explain why it is good practice to use a constant (e.g. VAT_RATE = 0.2) rather than writing the value 0.2 directly throughout a program.

medium

A variable is declared as: age = "16". What problem might this cause later in the program if age is used in a calculation like age + 1?

medium

What is the difference between declaring a variable and assigning a value to it?

medium

Which of these is the most suitable data type for storing a product's price, e.g. ยฃ4.99?

easy

What are the three basic programming constructs?

easy

What is the difference between = and == in most programming languages?

easy

What does this pseudocode output? total โ† 0 FOR num IN [3, 6, 9] total โ† total + num ENDFOR OUTPUT total

medium

What is an infinite loop? How would you cause one accidentally?

medium

What is the difference between a FOR loop and a WHILE loop?

medium

Which programming construct would be used to repeatedly ask a user for input until they enter a valid value?

easy

Trace this pseudocode and state the final value of x: x โ† 1 WHILE x < 10 x โ† x * 2 ENDWHILE OUTPUT x

medium

Which of the following correctly demonstrates "sequence" as a programming construct?

easy

A program needs to check a student's grade and output "Pass" if it is 40 or above, or "Fail" otherwise. Which construct is needed, and write the pseudocode for it.

medium

What will the following pseudocode output? FOR i โ† 1 TO 3 IF i = 2 THEN OUTPUT "two" ELSE OUTPUT i ENDIF ENDFOR

medium

What is the purpose of a RETURN statement in a function?

medium

What is the difference between a procedure and a function?

medium

What is a "parameter" in the context of a function or procedure?

easy

Consider this function: FUNCTION double(num) RETURN num * 2 ENDFUNCTION What is the result of calling double(7)?

easy

Explain one advantage of breaking a program into functions/procedures rather than writing all the code in one block.

medium

A function is defined as: FUNCTION calculateArea(width, height). What are "width" and "height" examples of?

easy

Write pseudocode for a function called isEven that takes one parameter, num, and returns True if num is even and False otherwise.

medium

A procedure is defined as: PROCEDURE displayMessage(name). Which of the following calls is correct, assuming name is a string parameter?

easy

Explain what happens to a variable declared inside a function once the function finishes executing (assuming it is a "local" variable).

hard

Consider this function: FUNCTION addTax(price, taxRate) RETURN price + (price * taxRate) ENDFUNCTION What value is returned by addTax(100, 0.2)?

medium

What does the following Python code output? words = ["cat", "dog", "bird"] print(words[1])

easy

What is a one-dimensional array?

easy

Given the array scores = [45, 67, 23, 89], what is the value of scores[2]?

easy

What is a two-dimensional (2D) array best used to represent?

medium

Given a 2D array grid where grid[1][2] = 9, explain what the two indices 1 and 2 represent.

medium

Write pseudocode to declare a 1D array called temperatures that can store 7 integer values, and set every value to 0.

medium

A program stores student names in a 1D array called names, with 30 elements (indices 0 to 29). Which pseudocode would correctly output every name?

medium

Explain why a 2D array would be more appropriate than several separate 1D arrays for storing a seating plan in a classroom with rows and columns of desks.

hard

Given the 2D array board = [[1,2,3],[4,5,6],[7,8,9]], what is the value of board[2][0]?

medium

Write pseudocode using a nested FOR loop to output every element of a 2D array called grid, which has 3 rows and 4 columns.

hard

What is concatenation? Write a Python example.

easy

What does the following Python code output? name = "Computing" print(len(name))

easy

What is a "substring"?

easy

What does the following Python code output? word = "Python" print(word[0:3])

medium

What does the following Python code output? name = "computer science" print(name.upper())

easy

Write a line of pseudocode or Python that concatenates the strings "Hello, " and a variable called name, and stores the result in a variable called greeting.

easy

A string variable contains " Hello " with extra spaces at the start and end. Which type of string operation would remove these extra spaces?

medium

Given the string fullName = "Ada Lovelace", write pseudocode/Python to extract just the first name ("Ada"), explaining which string function(s) you would need.

hard

What does the following code output? word = "code" print(word + word.upper())

medium

Explain why string manipulation functions like length, substring, and case conversion are useful when validating user input, such as a username.

hard

What is the purpose of opening a file in "write" mode?

easy

Why is it important to close a file after a program has finished reading from or writing to it?

medium

What is the difference between "write" mode and "append" mode when opening a file?

medium

Write pseudocode to open a file called "scores.txt" for reading, read one line from it, and store the line in a variable called data.

medium

A program needs to read every line from a text file called "names.txt" and output each one. What programming construct would typically be used alongside file reading commands to achieve this?

medium

What does "EOF" stand for, and why is it useful when reading from a file?

medium

Write pseudocode that opens a file called "log.txt" in append mode and writes the string "Login successful" to it as a new line.

medium

A program reads data from "records.txt" but the file does not exist on the computer. What is most likely to happen?

medium

Explain one advantage of storing data in a text file rather than only keeping it in variables while a program runs.

medium

A program writes each new high score to a file called "highscores.txt" every time it is run, without deleting previous scores. Which file mode should be used, and why?

medium