Font size
Worksheets2.2 Programming Techniques
Total questions: 76
Worksheet time: 38mins
What is a variable?
Answers: 2
A value stored in a region of memory using an identifier.
The value can change during the duration of the program running.
The value can not change during the duration of the program running.
What is a constant?
Answers: 2
A value stored in a region of memory using an identifier.
The value can change during the duration of the program running.
The value can not change during the duration of the program running.
Variables are defined using which operator
=
==
Which of the following is a constant?
const vat = 2
vat = 2
Which of the following are logical operators
Answers: 3
AND
OR
NOT
DIV
MOD
Which of the following adds?
+
-
*
/
Which of the following subtracts?
+
-
*
/
Which of the following multiplies?
+
-
*
/
Which of the following divides?
+
-
*
/
Which of the following performs integer division?
DIV
MOD
^
/
Which of the following performs integer division and finds the remainder in python?
DIV
MOD
%
/
Which of the following calculates the power?
DIV
MOD
^
/
Which is the equal to operator
=
!=
==
Which is the assignment operator
=
!=
==
Which is the less than operator
<
<=
>=
>
Which is the greater than operator
<
<=
>=
>
Which is the less than or equal to operator
<
<=
>=
>
Which is the greater than or equal to operator
<
<=
>=
>
Which of the following would ask for an input and store it so it can be used later?
Answers: 2
input("prompt to user")
input()
variable = input("prompt to user")
variable = input()
Which of the following is a valid print statement?
Answers: 2
print("Hello World")
print "Hello World"
variable = "Hello World"
print (variable)
variable = "Hello World"
print variable
variable = "Hello World"
print(Hello World)
What are the three basic structures of programming?
Answers: 3
Coding
Sequencing
Selection
Iteration
Prints
Which best describes sequence.
Answers: 2
Carrying out a task as a set of steps
The order the steps take place in is important.
Selecting which sections of code to run based on a condition.
Will repeat code a set number of times or while a condition is true.
Which best describes selection.
Answers: 2
Carrying out a task as a set of steps
Will be carried out with if/else and switch/case.
Selecting which sections of code to run based on a condition.
Will repeat code a set number of times or while a condition is true.
Will be carried out with for, while and do until.
Which best describes iteration.
Answers: 2
Carrying out a task as a set of steps
Will be carried out with if/else and switch/case.
Selecting which sections of code to run based on a condition.
Will repeat code a set number of times or while a condition is true.
Will be carried out with for, while and do until.
Which of the following blocks of code is an example of a sequence?
Which of the following blocks of code is an example of a selection?
Answers: 2
Which of the following blocks of code is an example of a iteration?
Answers: 3
Which is an example of a if/else selection.
Which is an example of a switch case selection.
Which is an example of a while loop?
Which is an example of a for loop?
Which is an example of do until loop?
Which loop will loop for a set number of times? (Count Controlled)
For
While
Do...Until
Which loop will loop whilst a condition is true?
For
While
Do...Until
Which loop will loop whilst a condition is false?
For
While
Do...Until
If you want a condition controlled loop to loop at least once which type of loop should you use?
For
While
Do...Until
Which is an example of finding the length of a string?
someText="Computer Science"someText.length // returns 16 (includes space)
someText="Computer Science"someText.substring(3,3) // "returns "put"
someText="Computer Science"
sometext.upper // returns "COMPUTER SCIENCE"
sometext.lower // returns "computer science"
ASC("A") // Returns 65
CHR(65) // Returns "A"
Which is an example of extracting part of a string?
someText="Computer Science"someText.length // returns 16 (includes space)
someText="Computer Science"someText.substring(3,3) // "returns "put"
someText="Computer Science"
sometext.upper // returns "COMPUTER SCIENCE"
sometext.lower // returns "computer science"
ASC("A") // Returns 65
CHR(65) // Returns "A"
Which is an example of converting the case of a string?
someText="Computer Science"someText.length // returns 16 (includes space)
someText="Computer Science"someText.substring(3,3) // "returns "put"
someText="Computer Science"
sometext.upper // returns "COMPUTER SCIENCE"
sometext.lower // returns "computer science"
ASC("A") // Returns 65
CHR(65) // Returns "A"
Which is an example of ASCII convertion to or from a character?
someText="Computer Science"someText.length // returns 16 (includes space)
someText="Computer Science"someText.substring(3,3) // "returns "put"
someText="Computer Science"
sometext.upper // returns "COMPUTER SCIENCE"
sometext.lower // returns "computer science"
ASC("A") // Returns 65
CHR(65) // Returns "A"
Which of the following files opens a file?
myFile = openRead("sample.txt")
myFile = openWrite("sample.txt")
myFile.readLine()
myFile.close()
myFile.writeLine()
Which of the following files opens a file to be read?
myFile = openRead("sample.txt")
myFile = openWrite("sample.txt")
myFile.readLine()
myFile.close()
myFile.writeLine()
Which of the following files opens a file to be written to?
myFile = openRead("sample.txt")
myFile = openWrite("sample.txt")
myFile.readLine()
myFile.close()
myFile.writeLine()
Which of the following reads a line from a file?
myFile = openRead("sample.txt")
myFile = openWrite("sample.txt")
myFile.readLine()
myFile.close()
myFile.writeLine()
Which of the following writes a line to a file?
myFile = openRead("sample.txt")
myFile = openWrite("sample.txt")
myFile.readLine()
myFile.close()
myFile.writeLine("Hello World")
Which of the following closes a file?
myFile = openRead("sample.txt")
myFile = openWrite("sample.txt")
myFile.readLine()
myFile.close()
myFile.writeLine("Hello World")
Which of the following blocks of code will open and read each line from a file?
Which of the following blocks of code will open and write to file?
What does the code MyFile.endOfFile() do?
Answers: 2
Closes the file
Returns true if we have reached the end of the file?
Returns false if we have not reached the end of the file?
What is meant by a record?
Answers: 2
Each record stores data about a single person or thing.
Each record stores data about a multiple people and things.
Each record contains a number of fields. e.g Age, Firstname, Surname, Height, Weight
Each field contains a number of records. e.g Age, Firstname, Surname, Height, Weight
SELECT IdNum FROM employees
Which records will be returned?
1876
1114
1556
1354
1130
SELECT IdNum FROM employees
WHERE FName = "Jack"
Which records will be returned?
1876
1114
1556
1354
1130
SELECT IdNum FROM employees
WHERE FName LIKE "M%"
Which records will be returned?
1876
1114
1556
1354
1130
SELECT IdNum FROM employees
WHERE FName LIKE "M%" AND Salary > 30000
Which records will be returned?
1876
1114
1556
1354
1130
SELECT IdNum FROM employees
WHERE FName LIKE "J%" OR Salary > 40000
Which records will be returned?
1876
1114
1556
1354
1130
SELECT IdNUm, LName FROM employees
WHERE Salary > 40000 AND < 50000
Which records will be returned?
1876, CHIN
1114, GREENWALD
1556, PENNINGTON
1354, PARKER
1130, WOOD
array names[5]
names[0]="Ahmad"
names[1]="Ben"
names[2]="Catherine"
names[3]="Dana"
names[4]="Elijah"
print(names[3])
What name will be printed?
Ahmad
Ben
Catherine
Dana
Elijah
array names[5]
names[0]="Ahmad"
names[1]="Ben"
names[2]="Catherine"
names[3]="Dana"
names[4]="Elijah"
print(names[0])
What name will be printed?
Ahmad
Ben
Catherine
Dana
Elijah
array names[5]
names[0]="Ahmad"
names[1]="Ben"
names[2]="Catherine"
names[3]="Dana"
names[4]="Elijah"
print(names[5])
What will happen when this code runs?
Answers: 3
names[5] is out of range
the index only runs from 0 to 4
Catherinenames[5] is in range
the index runs from 1 to 5
An error will occur
Below is an example of defining a 2d array
array board[8,8]
board[0,0]="rook"
What is the highest index in this array?
board[8,8]
board[7,7]
Below is an example of defining a 2d array
array board[8,8]
board[0,0]="rook"
How would I loop through all elements in a 2D array
for x = 0 to 7
...for y = 0 to 7
...next y
next x
for x = 0 to 7
next x
for y = 0 to 7
next y
Which is an example of a subroutine being defined?
Answers: 2
function triple(number)
....return number*3
endfunction
procedure greeting(name)
....print("hello"+name)
endprocedure
y=triple(7)
greeting("Hamish")
Which is an example of a subroutine being called?
Answers: 2
function triple(number)
....return number*3
endfunction
procedure greeting(name)
....print("hello"+name)
endprocedure
y=triple(7)
greeting("Hamish")
Which is an example of a function being defined?
function triple(number)
....return number*3
endfunction
procedure greeting(name)
....print("hello"+name)
endprocedure
y=triple(7)
greeting("Hamish")
Which is an example of a procedure being defined?
function triple(number)
....return number*3
endfunction
procedure greeting(name)
....print("hello"+name)
endprocedure
y=triple(7)
greeting("Hamish")
What is the difference between functions and prodedures
Functions return values
Procedures return values
Procedures don't return values
Functions don't return values
variable = "Hello"
What type of data is this?
Integer
Real
Boolean
Character
String
variable = 'H'
What type of data is this?
Integer
Real
Boolean
Character
String
variable = 20.0
What type of data is this?
Integer
Real
Boolean
Character
String
variable = 20
What type of data is this?
Integer
Real
Boolean
Character
String
variable = True
What type of data is this?
Integer
Real
Boolean
Character
String
I want to turn "3" into 3.
Which cast should I use?
str(3)
int("3")
float("3")
I want to turn "3.0" into 3.0
Which cast should I use?
str(3.0)
int("3.0")
float("3.0")
I want to turn 3 into "3".
Which cast should I use?
str(3)
int("3")
float("3")
I want to turn 3.0 into "3.0"
Which cast should I use?
str(3.0)
int("3.0")
float("3.0")
Which of the following performs integer division?
DIV
MOD
^
/
