A structured, organised collection of data that is stored so that it can be searched quickly
Which term describes one row of a table, holding all the data about a single item?
Record
Which term describes a search of a database table that states which fields to show and which records to include?
Query
What is meant by the asterisk symbol when it is written after SELECT?
It shows every field of each record that is returned
Which SQL command names the table that the data is to be taken from?
FROM
What is meant by WHERE in an SQL query?
It gives the condition that each record must meet to be included in the result
Which SQL keyword is followed by the list of fields that are to be shown?
SELECT
In a database, which term describes one set of records about a single kind of thing, held in rows and columns?
A table
In a database table, what is a column such as Title or Price called?
A field
What does a SQL query do to the table it searches?
It returns the matching records and leaves the table unchanged
Which three keywords are used to write a SQL query?
SELECT, FROM and WHERE
The table Games has the fields Title, Genre, Price and AgeRating and holds the records shown. Which titles are returned by the query SELECT Title FROM Games WHERE Genre <> 'Racing'?
Castle Siege, Farm Life and Shadow Quest
Which query returns the titles of the games that are rated 3 and cost more than 15?
SELECT Title FROM Games WHERE AgeRating = 3 AND Price > 15
The table Games has the fields Title, Genre, Price and AgeRating and holds the records shown. Which titles are returned by the query SELECT Title FROM Games WHERE Genre = 'Racing' OR Price > 30?
Space Race, Speed Kart, Castle Siege and Shadow Quest
Which query returns the title of every game that is rated 12 or over?
SELECT Title FROM Games WHERE AgeRating >= 12
Which WHERE condition correctly searches for records where the genre is Strategy?
WHERE Genre = 'Strategy'
What does the query SELECT Title FROM Games return?
The title of every record in the Games table
The table Games has the fields Title, Genre, Price and AgeRating and holds the records shown. Which records does SELECT Title, Price FROM Games WHERE Price < 25 return?
The title and price of Space Race, Speed Kart and Farm Life
Which WHERE condition returns the games that cost 20 or less, including any game that costs exactly 20?
WHERE Price <= 20
Which WHERE condition correctly searches for games that have an age rating of 12?
WHERE AgeRating = 12
The Games table has the fields GameID, Title, Genre, Price and AgeRating. A query is written as SELECT Title FROM Games WHERE Genres = 'Racing'. Why does the query not work?
The field name Genres is not the name of a field in the table
The query SELECT Title FROM Games WHERE Genre = 'Racing' AND Price < 20 returns the racing games that cost less than 20. Which change would make the query return more games?
Using OR instead of AND
Which query returns the title and price of every game that is rated 3?
SELECT Title, Price FROM Games WHERE AgeRating = 3
What is meant by exponentiation?
Raising a number to a power by multiplying it by itself
Which symbol is used in Python to raise a number to a power?
**
What is meant by integer division (//)?
It gives the whole number of times one value goes into another
Which term describes the type of value always produced by the / operator, for example 3.5 or 4.0?
Real
What is meant by the multiplication operator (*)?
It finds the total when one number is added to itself a number of times
What does the + operator do when it is used with two strings?
It joins the two strings together into one string
When both values used are integers, which type of answer do the +, -, * and // operators give?
Integer
What is the result of 7 + 2?
9
What is the result of 12 - 5?
7
What is the result of 7 * 2?
14
What is the result of 7 / 2?
3.5
Which operator gives the remainder after whole-number division?
%
What is the result of 100 // 7?
14
Why does 8 / 2 give the answer 4.0?
Because the / operator always gives a real answer
When 12 % 3 is calculated, why is the answer 0?
Because 3 divides 12 exactly with nothing left over
What is the result of 3 // 10?
0
A student types 2 ^ 3 in Python, expecting the answer 8, but does not get 8. Why is this?
Because ^ is a different operator in Python, so 2 ** 3 is needed
17 sweets are shared equally between 5 people, so each person gets 3 sweets and 2 sweets are left over. Which calculation checks that none of the sweets have been lost?
5 * 3 + 2 = 17
What is the result of 7.0 // 2?
3.0
What is the result of 5 ** 2?
25
What is the result of 7 % 2?
1
Which term is the name of the operator that gives the amount left over after whole-number division?
Modulo
What is the name for operators that compare two values, such as == and != ?
Comparison operator
What is meant by the operator ==?
It checks whether two values are equal
Which operator gives the result True when two values are not the same?
!=
What is meant by the operator >= ?
It is True when the left value is at least the right value
What is the name for the result of a comparison, which can only be True or False?
Boolean
What is meant by a boundary value in a comparison?
The value exactly on the limit being tested
What is meant by the operator < ?
It is True when the left value is smaller than the right value
In Python, what happens in the statement x = 5?
It stores the value 5 in the variable x
Which pair of symbols is NOT a valid comparison operator in Python?
=< and =>
With x = 12 and y = 8, what is the value of x * 2 > y * 3?
False
A program compares a word typed by the user with 'Yes' using word == 'Yes'. The user types 'yes'. What is the result?
False, because == is case sensitive
The user types 10 when this program runs. What is the result of the comparison?
False, because the input is a string
With score = 45, what is stored in the variable passed by the statement passed = score >= 50?
The Boolean value False
A bag can hold a maximum load of 5 kg. Which condition is True for every load the bag can hold?
Weight <= 5
What does this program print?
False
A loop keeps repeating while the condition answer != 'Correct' is True. Which value of answer makes the condition False?
'Correct'
With x = 4 and y = 9, which comparison gives True?
X < y
What does this program print?
Pass is printed
Which Boolean operator gives True only when both of its conditions are True?
AND
Which Boolean operator gives True when at least one of its conditions is True?
OR
What is meant by 'Boolean'?
A value that is either True or False
What is meant by 'condition'?
An expression that evaluates to True or False
What is meant by a 'compound condition'?
Two or more conditions joined by Boolean operators
What does the not operator do to a condition?
Reverses it, so True becomes False
A program stores a score that can be any whole number from 0 to 100. Which condition is True only for scores in this range?
Score >= 0 and score <= 100
Which condition is True only for scores that are outside the range 0 to 100?
Score < 0 or score > 100
A program must check whether the variable x holds the value 1 or the value 2. Which condition does this correctly?
X == 1 or x == 2
A variable called colour holds the value blue. Which expression evaluates to True?
Not (colour == 'red')
A Boolean variable called found holds the value False. Which condition is True?
Not found
In a condition that uses not, and and or, in which order are the operators worked out?
Not, then and, then or
Which condition is True only for a member who is under 12 or over 65?
(age < 12 or age > 65) and member == 'yes'
A variable x holds the value 5. Which condition gives the result True?
X > 3 and x < 10
A programmer writes score >= 0 and <= 100 to check that a score is in the range 0 to 100, but the program reports an error. Why?
The second comparison does not name score
A program prints Success only when the username is admin and the password is guest. Which condition does this?
Username == 'admin' and password == 'guest'
A variable score holds the value 30. Which condition gives the result True?
Score >= 50 or score < 40
A condition joins two comparisons with or and gives the result False. What must be true?
Both of the comparisons are False
Which term describes a named location in memory that holds a value which can change while the program is running?
Variable
What is meant by a temporary variable?
A variable used to hold one value briefly while two other values are swapped
Which term describes the process of giving a value to a variable using the = symbol?
Assignment
Which term describes a variable whose value is increased by adding each new amount to the value that it already holds?
Running total
Which term describes a variable name such as totalCost, where the words are joined and each word after the first begins with a capital letter?
CamelCase
Which term describes a word such as if or while that Python keeps for its own use and that cannot be used as a variable name?
Keyword
Which characters may be used in a Python variable name?
Letters, digits and underscores
A program runs the line total = total + price, but total has never been given a value. What is the problem?
Total has no value, so the program stops with an error
The variable score holds the value 10. What is displayed by print('score')?
The word score
What does this program print?
4
What does this program print?
10 then 6
What does this program print?
3 then 7
Which of these is NOT a valid variable name in Python?
Total cost
In the line area = 3.142 * radius * radius, which names are the variables?
Both area and radius
A programmer needs a variable to store the score of the current player. Which name is best?
PlayerScore
A variable called score holds the value 10. The program then runs the line score = 25. What happens to the value 10?
It is replaced by 25 and lost
A programmer writes the line 2ndScore = 10 in a program, but the line causes an error. Why?
A variable name cannot start with a digit
A program counts how many items it has processed, using a variable called count. Which line increases count by one and stores the new value?
Count = count + 1
A program stores the length of a rectangle in length and its width in width. Which line calculates the area and stores it in the variable area?
area = length * width
Which term describes the data that a program sends out, such as text shown on the screen?
Output
What is meant by a string?
A sequence of characters treated as text, written inside quotation marks in a program
Which term describes a combination of values and operators, such as 3 + 4, that is worked out before its result is displayed?
Expression
Which term describes the marks that must be placed at both ends of a piece of text in a print() call?
Quotation marks
What is meant by Python being case sensitive?
Capitals and small letters are treated as different characters
What is meant by printing a variable?
Displaying the value that is stored in the variable
What does the print() function do when a Python program runs?
It displays output on the screen
A program contains the line print('total'). What appears on the screen?
The word total
What appears on the screen when print(3 + 4) runs?
The number 7
What appears on the screen when print('Good' + 'morning') runs?
Goodmorning
A variable called age holds the value 15. What appears on the screen when print('Age:', age) runs?
Age: 15
A program contains the line print('Age: ' + 15). What happens when the program runs?
An error stops the program
A print line has a single quotation mark at the start of the text and a double quotation mark at the end. Why does the program stop with an error?
The quotation marks at each end do not match
In Python, why does the line print 'Hello' stop with an error?
The brackets around the text are missing
What does this program print?
The words cat and dog on separate lines
What does this program print?
A, then a blank line, then B
A student writes print(Hello) so that the word Hello will appear on the screen, but the program stops with an error. Why?
Hello is read as a variable name that has no value stored in it
What does this program print?
7 on the first line, then the text 3 + 4
A program draws a shape made of stars using one print() call for each line of the shape. Why is a separate print() call used for each line?
Each print() call puts its output on a new line
Which term describes converting a value from one data type to another data type?
Casting
What does the casting function int() do when it is applied to the string '42'?
It converts the string into an integer for use in calculations
Which casting function converts a string such as '4.52' into a real number?
The float() function, which keeps the decimal part
What is meant by the casting function str()?
It converts a value into a string so that it can be joined to text
What is meant by truncating a real number when it is cast to an integer?
The fractional part is cut off, so 4.99 becomes 4
Which value gives False when it is cast with bool()?
The empty string
A variable called score holds the integer 10. The statement float(score) runs on its own. What does score hold afterwards?
The integer 10
A value typed in by the user is stored as a string. Why must int() be used on it before it is used in a calculation?
The value is a string, so it must become a number for arithmetic
What is the value of bool('False')?
True
What is the result of int('12') + int('3')?
15
What is the value of float(7)?
7.0
Which of these will cause the program to stop with an error when int() is used on it?
The string '3.5'
A program runs the code int('7') + '3'. What happens?
The program stops with an error
A variable called answer holds the string 'False'. A program needs the Boolean value False. What should it do?
Compare answer with the text 'False'
The variable price holds the string '2.5'. What is the value of float(price) + 2?
4.5
What is the result of str(12) + str(3)?
The text '123'
Which term describes the message shown on screen that tells the user what to type before the program waits for their entry?
Prompt
Which term describes data typed on the keyboard and read into a program while it is running?
Input
Which term describes the type of value that input() always returns, even when the user types digits?
String
What is meant by the input() function?
It shows a prompt, waits for the user to type and press Enter, then gives back what was typed as a string
What is meant by concatenation?
Joining two or more strings together to make one longer string
Why should a prompt usually end with a space, as in input('Enter your age: ')?
So the user's typing does not run into the prompt text
A program must add a whole number typed by the user to another number. Which line stores the typed value correctly?
Number = int(input('Enter a whole number: '))
A program needs a height in metres, such as 1.67. Which line stores the typed value so it can be used in a calculation?
Height = float(input('Height in metres: '))
The user types 3. What does this program print?
90
A program asks for a first name and a surname, then runs print('Hello ' + firstName + ' ' + surname). The user types Ali then Khan. What is printed?
Hello Ali Khan
A program asks for a length in metres and converts the typed value using int(). A user types the word ten. What happens?
The program stops with an error
A program contains the line input('Enter your name: ') with nothing before it. What is the effect of this line?
The name is read from the keyboard but is not kept for later use
A prompt is on the screen and the user has typed 15 but has not pressed Enter. What is true at this moment?
The program is still waiting and the value is not stored yet
The user types 15. What does this program print?
1515
The user types 4 and then 9. What does this program print?
13
A program needs a height in metres, such as 1.67. Which reason explains why the prompt should mention metres and give an example value?
It tells the user which unit and form to type in
What is the name for a combination of values, variables and operators that is worked out to give a single value?
Expression
What is the name for the action of working out the value on the right of the equals sign and storing it in the variable named on the left?
Assignment
What is the name for the symbol in a calculation that shows which mathematical process is to be carried out on the values it is used with?
Operator
What is meant by the order of operations?
The rules that fix the sequence in which the parts of a calculation are worked out
What is meant by the remainder?
The value that is left over when one whole number is divided by another and the answer is given as a whole number
A program works through a list of prices and keeps adding each price to a variable called total, using lines such as total = total + price. What is this called?
A running total
When an expression contains several operators of the same priority, such as * and /, in which order are they worked out?
From left to right
What is the value of the expression 2 + 3 * 4?
14
What does this program print?
5.0
PI is 3.142 and radius is 10. What is the value of PI * radius ** 2?
314.2
What does this program print?
68.0
What does this program print?
20
What does this program print?
2 and 15
What does this program print?
48.0
A program reads two values with input() and stores them without converting them. The user types 3 and then 4. What does the program print for a + b?
34
Which of these calculations causes an error when the program runs?
9 / 0
A student writes 3 ^ 2 to work out 3 squared. Which expression should be used instead?
3 ** 2
What does this program print?
4 and 7
What does this program print?
1
The user types 4 and then 7. What does this program print?
28
A school has 50 pupils and each minibus has 16 seats. A program works out the number of minibuses needed so that every pupil has a seat. What is the smallest number of minibuses needed?
4
What does this program print?
3.5
Which term describes a pre-written collection of code that a program can bring in to add extra features, such as the one that creates random numbers?
Library
What is the name for creating values in a program that cannot be predicted and are different each time the program runs?
Random number generation
What is meant by random.randint(1, 6)?
A call that returns a whole number from 1 to 6, including both ends
What is meant by storing the value of random.randint(1, 6) in a variable?
Keeping the number so the same value can be used again later
Which line must appear at the top of a Python program so that random.randint can be used?
Import random
What values does random.random() return?
A real number from 0.0 up to but not including 1.0
A program needs to store a random real number from 5.0 up to but not including 10.0 in a variable called value. Which line should it use?
Value = 5 + random.random() * 5
A game rolls two separate dice with random.randint(1, 6) each and adds them. How does this differ from one call of random.randint(2, 12)?
Totals near 7 are more likely with two separate dice
Which line gives a value that could represent the two possible outcomes of a coin toss?
Coin = random.randint(0, 1)
A program calls random.randint(1, 6) but does not start with import random. What happens?
A NameError is reported when the line is run
A program picks six lottery numbers using six separate calls of random.randint(1, 49). Why is this not suitable for a real lottery?
The same number can be picked more than once
A program stores random.randint(1, 100) in a variable and then prints the value doubled. What could the output be?
A whole number from 2 to 200
Which of these programs needs to produce values that are different each time it runs?
A program that rolls dice for a game
How many times should import random appear in a program that creates random numbers in several places?
Once, at the top of the program
This program rolls two dice. Which totals can be printed?
Any whole number from 2 to 12
Why must a program import the random library before random.randint can be used?
The function is held in the library, not built in
Which term describes the programming construct in which a condition is checked and its True or False result decides which block of code runs?
Selection
What is meant by elif in Python?
It adds another condition to an if statement, and its block runs only if the conditions above it were all False
What is the name for the part of an if statement, written on the same line as the if, that is checked to give a True or False result?
Condition
What is meant by nested selection?
One selection is written inside another, and the inner one is only checked when the outer condition leads to it
What is the name for the whitespace at the start of a line that shows which block the line belongs to?
Indentation
In Python, what is meant by a block of code?
The lines indented under an if, elif or else line
Which parts of an if, elif, else chain are always needed?
Only the if line and its block
What must be written at the end of an if line in Python?
A colon
In an if statement with an else part, when does the else block run?
When the condition on the if line is False
What does this program print?
Done
A student wants to add a second condition after the first if line in a selection. Which line should be written next?
elif score >= 50:
What does this program print?
Merit
The user types sun in lower case. What does this program print?
Weekday
What does this program print?
Too short to ride
In a nested selection, how must the inner if line be positioned?
Indented further than the outer if line
What happens if a program contains no selection statements?
It carries out the same steps every time it runs
A student writes Else: instead of else: in a selection. Why does the program fail to run?
The keyword must be written in lower case
In a nested selection, what happens to the inner if when the outer condition is False?
It is skipped, so its condition is never checked
A student writes if score = 70: instead of if score == 70:. What is the problem?
A single equals sign assigns a value instead of testing one
A program sets answer to a random whole number from 1 to 3, then prints Yes when answer is 1, No when it is 2, and Ask again later in the else block. What is true of one run?
The number decides which of the messages is printed
A program prints Merit for score == 50 and Fail in the else block. A score of 55 gets Fail. What change is needed?
Test score >= 50 instead of score == 50
What is meant by concatenation?
Joining two strings together to make one longer string
Which term describes taking part of a string between a start position and an end position?
Slicing
What is meant by an index?
The position of a character in a string
Which function returns the number of characters in a string?
len()
What does name.upper() produce?
A new string with all the letters changed to capitals
Which function converts a character into its ASCII code?
ord()
What is meant by a substring?
Part of a string, with its characters kept in order
What is meant by the code of a character?
The number that the character is stored as
In the string 'School', at which position is the letter 'h'?
2
How many characters are in the string 'Hi there!'?
9
The variable code holds the string 'ABCDEFGH'. What does code[2:5] give?
It gives CDE
The variable code holds the string 'GB2026LON'. Which slice gives the last three characters, LON?
It gives code[6:9]
A program runs print('4' + '5'). What happens?
It prints 45
The variable points holds the number 10. Which line prints Total: 10 without stopping with an error?
It runs print('Total: ' + str(points))
What does chr(ord('a') + 1) give?
B
Which line makes the variable name hold the uppercase version of its string?
It writes name = name.upper()
A username is built as surname[0:3].lower() + firstName[0:1].lower() + year[2:4], where year holds the text 2025. With surname Patel and firstName Sam, what is the username?
Pats25
A program reverses a word by looping through its characters, starting at the last position and finishing at the first. Why is result = result + word[i] written inside the loop?
To build the new string one character at a time
The variable word holds the string 'Python'. What does word[len(word) - 1] give?
N
The variable code holds the string 'GB2026LON'. Which slice gives the first two characters, GB?
code[:2]
A programmer needs the last four characters of a product code that may be different lengths. Why is code[len(code) - 4:] better than code[5:9]?
It works whatever the length of the code
A program asks the user to answer yes or no. Which condition accepts YES, Yes and yes?
if answer.lower() == 'yes'
A program loops through the characters of the word 'banana' and counts how many of them are vowels. What does it count?
3
What is meant by readability in a program?
The ease with which a programmer can understand what the code does
A program stores a value under a name, and that value is given a new value several times while the program runs. Which term describes that name?
Variable
What is meant by maintainability in a program?
How easily the code can be changed later without introducing mistakes
A program begins with the line PI = 3.142. The value is used in calculations later but is never given a new value while the program runs. Which term describes PI?
A constant
What is meant by a naming convention for constants?
An agreed way of writing constant names, such as using capital letters
Which of these describes a constant in a program?
A named value that does not change while the program runs
Which line sets a constant for the number of lives at the start of a game, following the Python convention?
MAX_LIVES = 3
A line inside a Python program gives a constant a new value. What happens when the program runs?
The new value is used, because Python allows the change
Where should a constant be set in a program?
Once, near the top of the program
A program uses the name VAT for the value 0.2 in a calculation. Why does this make the program easier to understand?
The name VAT shows what the value 0.2 means
A programmer types the value 0.2 into five different calculations. How does using a constant help prevent mistakes?
The value is written once, so it cannot be typed differently later
A program uses the constant PASS_MARK = 40 to check exam scores. The pass mark changes to 50. What must the programmer do?
Change the value on the line where PASS_MARK is set
A student's program uses the fixed value 3.142 in three different calculations. What should the student do?
Declare a constant PI once and use PI in every calculation
During the game, lives is reduced by one each time the player loses. Which statement about this program is correct?
MAX_LIVES is a constant and lives is a variable
A program records the results of a quiz. Which value should be stored as a variable rather than a constant?
The current score of the player
A program asks the user to type in the weight of a parcel, then works out the cost of posting it. Which statement about the weight is correct?
It is a variable because it can be different each time the program runs
A program contains the line VAT = 0.2 near the top. Where does the value 0.2 come from?
It was written into the code by the programmer
A programmer writes DAYS_IN_WEEK = 7 at the top of a program. Why is a constant the right choice for this value?
The value stays the same for the whole run of the program
What is meant by 'iteration'?
Repeating a set of instructions in a program
What is meant by 'nesting'?
Putting one loop inside another loop
Which term describes the amount by which the loop variable changes on each pass of a FOR loop?
Step
Which term describes the values that a FOR loop counts through, from the start value up to but not including the stop value?
Range
What is meant by 'loop variable'?
The variable that takes each value in turn as the loop repeats
What is meant by the loop body?
The instructions that are repeated each time the loop runs
What is meant by the stop value of a range?
The value the loop stops before using
What does a count-controlled loop do in a program?
It repeats instructions a set number of times
A program must display the numbers 1 to 20, including 20. Which range should the FOR loop use?
Use range(1, 21)
What is the last value of i in for i in range(10, -1, -1)?
0
Which loop repeats its body zero times?
A loop using range(10, 0)
A program uses a FOR loop to add up five scores into a running total. Where should total = 0 be placed?
Before the loop starts
An outer FOR loop runs 3 times and the inner loop runs 4 times. How many times does the code inside the inner loop run?
12
A program stores a number typed by the user in count. Which range makes the loop body run exactly count times?
Use range(0, count)
A loop must visit every position of a word stored in word. Which range should be used?
Use range(0, len(word))
Which task is best carried out with a count-controlled loop?
Printing the seven times table from 1 to 12
In a FOR loop, which values does range(10) give?
0 to 9
What does the last pass of this program print?
72
A program adds four scores, 5, 7, 9 and 11, into a running total inside a FOR loop. It then works out the average of the scores after the loop. What is the average?
8
In the loop for i in range(0, 10, 3), which values does the loop variable take?
0, 3, 6, 9
What is meant by a condition-controlled loop?
A loop that repeats until a condition is met, rather than a set number of times
What is the name for a Boolean variable used to record whether something has happened, such as whether a loop should stop?
Flag
What is meant by a while loop?
A loop that checks its condition before each pass, so its body may run zero times
Which term describes a loop that runs forever because nothing inside it changes the value used in its condition?
Infinite loop
What is meant by a running total?
A variable that has each new value added to it, so it holds the sum of the values so far
What is the name for the variable a programmer sets before a loop and changes inside it to keep track of how many times the loop has run?
Counter
In Python, how does the computer know which lines make up the body of a while loop?
The lines indented under the while statement
What is meant by the condition of a while loop?
A Boolean expression that is either True or False
When is a condition-controlled loop the right choice instead of a count-controlled loop?
When the number of repeats is not known in advance
How many times does the body of this loop run?
Zero times
count starts at 1. The loop while count is less than or equal to 10: adds 1 to count on each pass. What is the value of count when the loop ends?
11
A loop starts with count = 1 and uses the condition while count is less than or equal to 10:, but the loop never ends. What is the cause?
Count is never given a new value inside the loop
A loop must always run its body at least once before an answer can be checked. When is the condition checked in this loop?
At the end of each pass
A loop begins with finished = False and while not finished:. The body asks the user for an answer. Which line at the end of the body sets the flag so the loop stops only when the answer is correct?
Finished = answer == 'Correct'
A guessing game uses the loop while guess != secret and attempts < 3:. When does this loop stop?
When the guess is right or three attempts have been used
A loop adds each number entered to a total and stops when 0 is entered. The user enters 5, 8, 3, then 0. What total is displayed?
Total: 16
In a loop that adds numbers until 0 is entered, the first input is read before the loop starts. Why is this done?
So the condition has a value to test
A loop uses while guess != secret or attempts < 3:. When does this loop stop?
When the guess is right and three attempts have been used
Two loops both keep asking for a guess until it is correct. One checks its condition before each pass, the other is set up to run at least once. The first guess is correct. What is the difference between the two loops?
The first loop skips its body, the second runs its body once
In a number guessing game, guess is set to 0 before the loop while guess != secret: runs. Why is this done?
So the condition is True at the first check and the body runs
A program uses while True: on purpose, so that it keeps running until the user closes it. Which statement about this loop is correct?
It repeats forever on purpose, so it is not a logic error
Which term describes a single value stored in an array?
Element
What is meant by 'index'?
The position of an element in an array, counting from 0
Which term describes a data structure that stores several values of one data type under a single identifier?
Array
What is meant by 'append'?
To add a new element to the end of a list
Which term describes the fault that stops a program when it tries to access a position outside the range of an array?
IndexError
In Python, how is a one-dimensional array written?
As a list in square brackets with the elements separated by commas
What does len(scores) give for a list called scores?
The number of elements in the list
What does this program print?
Green
After this program runs, which expression refers to the value 'Rome'?
Index 1, written cities[1]
Why is for i in range(0, len(scores)) used instead of for i in range(0, 5)?
It keeps working when the array holds a different number of elements
What does this program print?
25
Which value should a variable storing the highest value be set to before the loop that finds the highest element starts?
The first element of the array
What does this program print?
3
What does this program print?
['Blue', 'Pink', 'Green', 'Purple', 'Red']
scores = [4, 8, 15, 16, 23]. Which expression gives the last value, 23?
scores[len(scores) - 1]
Why is a set of scores usually stored in one array instead of in separate variables such as score1, score2 and score3?
One loop can process all the values through a single name
What does this program print?
[30, 100, 120, 100, 400]
Where is the first number entered by the user stored?
At index 0, because the loop starts with i set to 0
Which term describes a data structure that stores values in rows and columns, where each value can be found using two indexes?
Two-dimensional array
What is meant by a row in a two-dimensional array?
One inner list of the array, whose elements are all found using the same first index
Which term describes the elements that all sit at the same position in every inner list of a two-dimensional array, found by keeping the second index the same?
A column
What is meant by a list of lists in Python?
A structure where each item in the outer list is itself a list
What is meant by a nested loop?
One loop placed inside another, so that every element of a two-dimensional array can be visited
Which term describes a single value stored at one position in a two-dimensional array?
An element
A 2D array seatPlan holds 5 rows of seats with 8 seats in each row. What does len(seatPlan) give?
The number of rows in the 2D array
A 2D array marks stores marks for pupils. Each row is a pupil, each column is a test. Row 1 is [45, 60, 72, 50]. What is marks[1][2]?
72
A 2D array grid has 5 rows and 4 columns with indexes starting at 0. Which element is in the last row and last column?
grid[4][3]
A 2D array grid has 6 rows and 3 columns. What does len(grid[0]) return?
3
A 2D array stores exam marks for a class. What is true about the elements it can store?
All elements must be the same data type
A 2D array scores has rows for students and columns for tests. Row 2 is [10, 20, 30, 40]. What is the total for student 2?
100
A 2D array scores has rows for students and columns for tests. Column 1 contains 5, 10, 15, 20. What is the total for test 1?
50
A 2D array has 4 rows and 5 columns. Using nested loops to visit every element once, how many times does the inner loop body run?
20
A program uses nested loops to find the highest value in a 2D array and report its position. What must the program store as well as the highest value?
The row index and the column index
A program builds a 3 by 3 grid of dashes row by row in Python. What should be appended to the grid after each row is filled?
The completed row as a list
A 2D array Board holds a chess board, where each row and each column is a square. Which statement puts a pawn in row 1, column 0?
Board[1][0] = 'Pawn'
A 2D array scores holds marks for 2 pupils in 3 tests, with one row per pupil. The rows are [12, 8, 10] and [6, 14, 4]. What is the mean mark of pupil 1?
8
A 2D array grid holds 4 rows and 3 columns. A program runs print(grid[2]). What is printed?
All three values in row 2
A program must search a 2D array grid for the lowest value. What should the variable that holds the lowest value be set to before the loops start?
The value already stored in grid[0][0]
Which term describes a collection of related data items about one thing, stored together as a unit?
Record
What is the name for a single item of data within a record, such as a product ID or a price?
Field
Which term describes a collection of records that all have the same fields?
Table
What is meant by a record?
A collection of related fields that describe one item
What is meant by a two-dimensional array when it is used to store a table of records?
A list of lists in which the first index selects the record and the second index selects the field
In a table that holds records, what does each row and each column represent?
A row is a record and a column is a field
A table of records is stored in a 2D array called stock. What does len(stock[0]) return?
The number of fields in one record
A table is stored in a 2D array with columns 0 ProductID, 1 Name, 2 Price, 3 Stock. What is held in stock[1][2]?
The Price field of the second record
Every field of a record is stored as a string when the record is held in a Python list. Why is this?
An array can hold values of only one data type
This record is held in a list, where item[3] holds the stock. Which condition correctly tests whether the item is out of stock?
if int(item[3]) == 0
A program loops through every record in a table held in a 2D array and adds int(stock[i][3]) to a running total. What does the total represent?
The number of items held in stock
Which line correctly reduces the stock field of record i by one in a table held in a 2D array?
stock[i][3] = str(int(stock[i][3]) - 1)
A program searches a table of records for a matching product ID. Where should the message that no match was found be printed?
After the loop has finished, if no record matched
A shop stores its product data as records. Which is a reason for storing the data in this way?
The data about one product is kept together
A product record holds its ID as text, its price as a real number and its stock as a whole number. What does this show about the fields in a record?
They can hold different data types
This record is held in a list, where item[2] holds the price. Which condition correctly checks that the price is more than 1 pound?
if float(item[2]) > 1
A program asks for a product name in name and searches the table for it, where column 1 holds the name. Which condition correctly finds the matching record?
if stock[i][1] == name
A table holds the records P01 Pencil 0.45 120, P02 Ruler 0.99 40, P03 Eraser 0.30 0 and P04 Glue stick 1.25 15, with ProductID, Name, Price and Stock in that order. A loop prints stock[i][1] when int(stock[i][3]) == 0. What is printed?
Eraser
A program totals a numeric field into totalItems and then prints 'Items in stock: ' + str(totalItems). Why is str() used?
To turn the number into text that can be joined on
A table of records is held in a 2D array. Why must the program know which field is held in each column?
Each column is found by its index, not by its name
Which term describes the operation that connects a program to a file so that it can be used?
Open
Which term describes the point where there are no more lines left to read in a file?
End of file
Which term describes how a file is opened, for example to read it or to write it?
Mode
What is meant by 'readline()'?
A file method that returns the next line of a file as a string
What is meant by opening a file with the mode 'w'?
It creates the file if it does not exist and wipes anything already in it
What is meant by closing a file?
It finishes with the file and saves anything that was written
Which term describes a file of lines of characters that is kept in secondary storage?
Text file
What is meant by opening a file in the mode 'r'?
The file is read from the start and fails if it is missing
Which method is used to add each line read from a file to the end of an array?
append()
Why might a program store its data in a file rather than only in variables?
The data is kept after the program ends
Which is the correct order of the basic file handling operations?
Open, read or write, close
A program writes several lines to a file but ends without closing it. What is the likely effect?
Some of the written data may not be saved
What does readline() return when the end of the file is reached?
An empty string
Why is .strip() used on the value returned by readline()?
It removes the new line character from the end
A program writes five values to a text file, but when the file is opened all five are on one line. What is missing from each write?
A new line character
A loop that reads every line of a file never reads the next line inside the loop. What happens?
The loop never ends because the line never becomes empty
A file holds whole numbers, one on each line, and a program adds them to a total. Why is int() needed on each line?
Each line is read as a string
A file holds three lines, Red, Green and Blue. A program reads the first two into a and b, removes their new line characters, then prints b + a. What is printed?
GreenRed
A program stores a whole number in the variable total and writes it to a file with scoreFile.write(total). The program stops with an error. What should be done to fix it?
Total must be changed into a string with str()
A settings file always holds three lines: a name, a level and a sound setting, in that order. A program has called readline() once and stored the name. What does the next call to readline() return?
The level
A program reads a file that contains a blank line in the middle. What does readline() return when it reaches that blank line?
A new line character
A program opens a file, reads three lines and then closes it. Which value is used for those read and close operations?
The variable that holds the opened file
A program must read a file that could hold any number of lines, including none. Why is a while loop used rather than a set number of readline() calls?
It stops at the end of the file, whatever its length
What is meant by a sub program?
A named block of code that carries out one task
Which term describes a sub program that carries out a task but does not return a value?
Procedure
What is meant by a function?
A sub program that returns a value to the caller
What is the name for a variable in the definition of a sub program that receives a value passed in when it is called?
Parameter
What is meant by calling a sub program?
Running a sub program by writing its name and brackets
What is the name for the value that a function sends back to the code that called it?
Return value
A sub program called agePass has no parameters. How is it called?
By writing agePass()
Which line correctly defines a sub program called total that receives one value?
Def total(num):
A program calls a sub program and the sub program runs to its last line. Where does execution continue?
At the line after the call
What is the key difference between a function and a procedure?
A function returns a value, a procedure does not
A sub program only displays the final scores on screen and sends nothing back. Which type of sub program is it?
A procedure
What does this program print?
17
A sub program is defined as def multiply(num1, num2): and is called with multiply(4, 6). Which statement is true?
The parameter num1 receives 4 and num2 receives 6
A function returns True or False, and a call to it is written directly after if as the condition. Why does this work?
The returned value is used as the condition
Which of these is a reason for writing a program as sub programs?
A task used in several places is written once and called each time
A function is given an array of scores and returns a new array holding each score doubled. What is true of the array that was passed in?
It is not changed by the function
A program calls greet() on line 1, but def greet(): is written on line 5. What happens when the program runs?
An error occurs because the definition has not run yet
A sub program is defined as numberAdder but a later line calls NumberAdder(). What happens?
The call fails because the names do not match exactly
A function contains return result followed by a print line. What happens to the print line when the function is called?
It is not run because return ends the function
A function average(scores) uses len(scores) inside a loop. Why does this let the function work for arrays of different sizes?
It gives the number of elements in the array
A function is meant to return a value but it prints the value instead and has no return statement. What problem does this cause?
The calling code has no value to store or use
Which term describes the part of a program in which a variable can be used?
Scope
What is meant by a local variable?
A variable that is created inside a sub program and can only be used while that sub program runs
Which term describes data created in the main program that can be used in every part of the program, including all sub programs?
Global variable
What does the keyword global do when it is written at the start of a sub program?
It lets the sub program change a variable created in the main program
What is meant by a constant?
A value that does not change while the program runs and is named in capital letters
Which term describes a fixed value that is created inside a sub program and can only be used there?
Local constant
A sub program stores its result in a local variable. The main program then tries to print that variable. What happens?
The program stops with an error, because the variable does not exist there
A value is passed into a sub program through a parameter. What is the scope of that parameter?
It is local to the sub program it belongs to
Two different sub programs each create a local variable called total. Which statement is true?
They are separate variables that cannot affect each other
What does this program print?
It prints 10
A sub program only reads a global variable and never assigns to it. What does the sub program need?
Nothing, it can read the global variable directly
Where is a global variable created in a program?
In the main program, outside any sub program
Which is a benefit of using local variables rather than global ones?
The sub program can be tested and reused on its own
A program stores a running total in a global variable that many sub programs can change. Why can this make the program hard to debug?
Any sub program can change it, so a wrong value is hard to trace
A program creates a global variable called points. A procedure contains the line points = points + 5 and does not use the keyword global. What happens when the procedure is called?
The program stops with an error, because points is treated as local
A fixed tax rate of 0.2 is needed by four sub programs. What is the benefit of creating TAX_RATE = 0.2 once in the main program?
The value is set in one place, so it only has to be changed once
A game keeps the value of lives at 3 in the main program. A procedure starts with the line global lives and contains lives = lives - 1. After the procedure has been called twice, what does the main program print for lives?
1
In a game, the score is read and updated by several different sub programs. Why might the programmer use a global variable for the score?
The same value is needed by many parts of the program
A sub program creates some local variables while it runs. What happens to the memory they use when the sub program ends?
It is freed and can be used elsewhere
A program has a global variable called lives. Two different procedures both need to change it. Which statement is true?