wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

2.2 Programming Techniques

Total questions: 76

Worksheet time: 38mins

Name
Class
Date
1.

What is a variable?


Answers: 2

a)

A value stored in a region of memory using an identifier.

b)

The value can change during the duration of the program running.

c)

The value can not change during the duration of the program running.

2.

What is a constant?


Answers: 2

a)

A value stored in a region of memory using an identifier.

b)

The value can change during the duration of the program running.

c)

The value can not change during the duration of the program running.

3.

Variables are defined using which operator

a)

=

b)

==

4.

Which of the following is a constant?

a)

const vat = 2

b)

vat = 2

5.

Which of the following are logical operators


Answers: 3

a)

AND

b)

OR

c)

NOT

d)

DIV

e)

MOD

6.

Which of the following adds?

a)

+

b)

-

c)

*

d)

/

7.

Which of the following subtracts?

a)

+

b)

-

c)

*

d)

/

8.

Which of the following multiplies?

a)

+

b)

-

c)

*

d)

/

9.

Which of the following divides?

a)

+

b)

-

c)

*

d)

/

10.

Which of the following performs integer division?

a)

DIV

b)

MOD

c)

^

d)

/

11.

Which of the following performs integer division and finds the remainder in python?

a)

DIV

b)

MOD

c)

%

d)

/

12.

Which of the following calculates the power?

a)

DIV

b)

MOD

c)

^

d)

/

13.

Which is the equal to operator

a)

=

b)

!=

c)

==

14.

Which is the assignment operator

a)

=

b)

!=

c)

==

15.

Which is the less than operator

a)

<

b)

<=

c)

>=

d)

>

16.

Which is the greater than operator

a)

<

b)

<=

c)

>=

d)

>

17.

Which is the less than or equal to operator

a)

<

b)

<=

c)

>=

d)

>

18.

Which is the greater than or equal to operator

a)

<

b)

<=

c)

>=

d)

>

19.

Which of the following would ask for an input and store it so it can be used later?


Answers: 2

a)

input("prompt to user")

b)

input()

c)

variable = input("prompt to user")

d)

variable = input()

20.

Which of the following is a valid print statement?


Answers: 2

a)

print("Hello World")

b)

print "Hello World"

c)

variable = "Hello World"

print (variable)

d)

variable = "Hello World"

print variable

e)

variable = "Hello World"

print(Hello World)

21.

What are the three basic structures of programming?


Answers: 3

a)

Coding

b)

Sequencing

c)

Selection

d)

Iteration

e)

Prints

22.

Which best describes sequence.


Answers: 2

a)

Carrying out a task as a set of steps

b)

The order the steps take place in is important.

c)

Selecting which sections of code to run based on a condition.

d)

Will repeat code a set number of times or while a condition is true.

23.

Which best describes selection.


Answers: 2

a)

Carrying out a task as a set of steps

b)

Will be carried out with if/else and switch/case.

c)

Selecting which sections of code to run based on a condition.

d)

Will repeat code a set number of times or while a condition is true.

e)

Will be carried out with for, while and do until.

24.

Which best describes iteration.


Answers: 2

a)

Carrying out a task as a set of steps

b)

Will be carried out with if/else and switch/case.

c)

Selecting which sections of code to run based on a condition.

d)

Will repeat code a set number of times or while a condition is true.

e)

Will be carried out with for, while and do until.

25.

Which of the following blocks of code is an example of a sequence?

a)
b)
c)
d)
e)
26.

Which of the following blocks of code is an example of a selection?


Answers: 2

a)
b)
c)
d)
e)
27.

Which of the following blocks of code is an example of a iteration?


Answers: 3

a)
b)
c)
d)
e)
28.

Which is an example of a if/else selection.

a)
b)
c)
d)
e)
29.

Which is an example of a switch case selection.

a)
b)
c)
d)
e)
30.

Which is an example of a while loop?

a)
b)
c)
d)
e)
31.

Which is an example of a for loop?

a)
b)
c)
d)
e)
32.

Which is an example of do until loop?

a)
b)
c)
d)
e)
33.

Which loop will loop for a set number of times? (Count Controlled)

a)

For

b)

While

c)

Do...Until

34.

Which loop will loop whilst a condition is true?

a)

For

b)

While

c)

Do...Until

35.

Which loop will loop whilst a condition is false?

a)

For

b)

While

c)

Do...Until

36.

If you want a condition controlled loop to loop at least once which type of loop should you use?

a)

For

b)

While

c)

Do...Until

37.

Which is an example of finding the length of a string?

a)

someText="Computer Science"someText.length // returns 16 (includes space)

b)

someText="Computer Science"someText.substring(3,3) // "returns "put"

c)

someText="Computer Science"

sometext.upper // returns "COMPUTER SCIENCE"

sometext.lower // returns "computer science"

d)

ASC("A") // Returns 65

CHR(65) // Returns "A"

38.

Which is an example of extracting part of a string?

a)

someText="Computer Science"someText.length // returns 16 (includes space)

b)

someText="Computer Science"someText.substring(3,3) // "returns "put"

c)

someText="Computer Science"

sometext.upper // returns "COMPUTER SCIENCE"

sometext.lower // returns "computer science"

d)

ASC("A") // Returns 65

CHR(65) // Returns "A"

39.

Which is an example of converting the case of a string?

a)

someText="Computer Science"someText.length // returns 16 (includes space)

b)

someText="Computer Science"someText.substring(3,3) // "returns "put"

c)

someText="Computer Science"

sometext.upper // returns "COMPUTER SCIENCE"

sometext.lower // returns "computer science"

d)

ASC("A") // Returns 65

CHR(65) // Returns "A"

40.

Which is an example of ASCII convertion to or from a character?

a)

someText="Computer Science"someText.length // returns 16 (includes space)

b)

someText="Computer Science"someText.substring(3,3) // "returns "put"

c)

someText="Computer Science"

sometext.upper // returns "COMPUTER SCIENCE"

sometext.lower // returns "computer science"

d)

ASC("A") // Returns 65

CHR(65) // Returns "A"

41.

Which of the following files opens a file?

a)

myFile = openRead("sample.txt")

b)

myFile = openWrite("sample.txt")

c)

myFile.readLine()

d)

myFile.close()

e)

myFile.writeLine()

42.

Which of the following files opens a file to be read?

a)

myFile = openRead("sample.txt")

b)

myFile = openWrite("sample.txt")

c)

myFile.readLine()

d)

myFile.close()

e)

myFile.writeLine()

43.

Which of the following files opens a file to be written to?

a)

myFile = openRead("sample.txt")

b)

myFile = openWrite("sample.txt")

c)

myFile.readLine()

d)

myFile.close()

e)

myFile.writeLine()

44.

Which of the following reads a line from a file?

a)

myFile = openRead("sample.txt")

b)

myFile = openWrite("sample.txt")

c)

myFile.readLine()

d)

myFile.close()

e)

myFile.writeLine()

45.

Which of the following writes a line to a file?

a)

myFile = openRead("sample.txt")

b)

myFile = openWrite("sample.txt")

c)

myFile.readLine()

d)

myFile.close()

e)

myFile.writeLine("Hello World")

46.

Which of the following closes a file?

a)

myFile = openRead("sample.txt")

b)

myFile = openWrite("sample.txt")

c)

myFile.readLine()

d)

myFile.close()

e)

myFile.writeLine("Hello World")

47.

Which of the following blocks of code will open and read each line from a file?

a)
b)
48.

Which of the following blocks of code will open and write to file?

a)
b)
49.

What does the code MyFile.endOfFile() do?


Answers: 2

a)

Closes the file

b)

Returns true if we have reached the end of the file?

c)

Returns false if we have not reached the end of the file?

50.

What is meant by a record?


Answers: 2

a)

Each record stores data about a single person or thing.

b)

Each record stores data about a multiple people and things.

c)

Each record contains a number of fields. e.g Age, Firstname, Surname, Height, Weight

d)

Each field contains a number of records. e.g Age, Firstname, Surname, Height, Weight

51.

SELECT IdNum FROM employees


Which records will be returned?

a)

1876

b)

1114

c)

1556

d)

1354

e)

1130

52.

SELECT IdNum FROM employees

WHERE FName = "Jack"


Which records will be returned?

a)

1876

b)

1114

c)

1556

d)

1354

e)

1130

53.

SELECT IdNum FROM employees

WHERE FName LIKE "M%"


Which records will be returned?

a)

1876

b)

1114

c)

1556

d)

1354

e)

1130

54.

SELECT IdNum FROM employees

WHERE FName LIKE "M%" AND Salary > 30000


Which records will be returned?

a)

1876

b)

1114

c)

1556

d)

1354

e)

1130

55.

SELECT IdNum FROM employees

WHERE FName LIKE "J%" OR Salary > 40000


Which records will be returned?

a)

1876

b)

1114

c)

1556

d)

1354

e)

1130

56.

SELECT IdNUm, LName FROM employees

WHERE Salary > 40000 AND < 50000


Which records will be returned?

a)

1876, CHIN

b)

1114, GREENWALD

c)

1556, PENNINGTON

d)

1354, PARKER

e)

1130, WOOD

57.

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?

a)

Ahmad

b)

Ben

c)

Catherine

d)

Dana

e)

Elijah

58.

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?

a)

Ahmad

b)

Ben

c)

Catherine

d)

Dana

e)

Elijah

59.

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

a)

names[5] is out of range

b)

the index only runs from 0 to 4

c)

Catherinenames[5] is in range

d)

the index runs from 1 to 5

e)

An error will occur

60.

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?

a)

board[8,8]

b)

board[7,7]

61.

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

a)

for x = 0 to 7

...for y = 0 to 7

...next y

next x

b)

for x = 0 to 7

next x

c)

for y = 0 to 7

next y

62.

Which is an example of a subroutine being defined?


Answers: 2

a)

function triple(number)

....return number*3

endfunction

b)

procedure greeting(name)

....print("hello"+name)

endprocedure

c)

y=triple(7)

d)

greeting("Hamish")

63.

Which is an example of a subroutine being called?


Answers: 2

a)

function triple(number)

....return number*3

endfunction

b)

procedure greeting(name)

....print("hello"+name)

endprocedure

c)

y=triple(7)

d)

greeting("Hamish")

64.

Which is an example of a function being defined?

a)

function triple(number)

....return number*3

endfunction

b)

procedure greeting(name)

....print("hello"+name)

endprocedure

c)

y=triple(7)

d)

greeting("Hamish")

65.

Which is an example of a procedure being defined?

a)

function triple(number)

....return number*3

endfunction

b)

procedure greeting(name)

....print("hello"+name)

endprocedure

c)

y=triple(7)

d)

greeting("Hamish")

66.

What is the difference between functions and prodedures

a)

Functions return values

b)

Procedures return values

c)

Procedures don't return values

d)

Functions don't return values

67.

variable = "Hello"


What type of data is this?

a)

Integer

b)

Real

c)

Boolean

d)

Character

e)

String

68.

variable = 'H'


What type of data is this?

a)

Integer

b)

Real

c)

Boolean

d)

Character

e)

String

69.

variable = 20.0


What type of data is this?

a)

Integer

b)

Real

c)

Boolean

d)

Character

e)

String

70.

variable = 20


What type of data is this?

a)

Integer

b)

Real

c)

Boolean

d)

Character

e)

String

71.

variable = True


What type of data is this?

a)

Integer

b)

Real

c)

Boolean

d)

Character

e)

String

72.

I want to turn "3" into 3.


Which cast should I use?

a)

str(3)

b)

int("3")

c)

float("3")

73.

I want to turn "3.0" into 3.0


Which cast should I use?

a)

str(3.0)

b)

int("3.0")

c)

float("3.0")

74.

I want to turn 3 into "3".


Which cast should I use?

a)

str(3)

b)

int("3")

c)

float("3")

75.

I want to turn 3.0 into "3.0"


Which cast should I use?

a)

str(3.0)

b)

int("3.0")

c)

float("3.0")

76.

Which of the following performs integer division?

a)

DIV

b)

MOD

c)

^

d)

/