Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Variables, Arrays, For Loops, and Functions Review

Total questions: 35

Worksheet time: 21mins

Name
Class
Date
1.

In computers science, variables:

a)

are numbers like pi

b)

represent parts of an experiment that are measured or tested

c)

are placeholders for storing information

d)

are unchangeable

2.

I can name my variable player1

a)

True

b)

False

3.

I can name my variable player 1

a)

True

b)

False

4.

Which of the following variables is NOT string type?

a)

character = "Dr."

b)

vehicle = "Ambulance"

c)

speed = 27

d)

lives = "3"

5.

What would be the new value of a after running the program:

var a = 3;

var b = 5;

a = a*b;

a)

8

b)

3

c)

15

d)

75

6.

What would be the value of "var_x" after this statement runs: var_x = 4+2

a)

3

b)

4+2

c)

6

d)

12

7.

What would be the value of "var_x" after this statement runs: var_x = "3+3"

a)

3

b)

3+3

c)

6

d)

var_x = "3+3"

8.
The first element in an array is always element 1.
a)
False
b)
True
9.
Values in arrays cannot be changed.
a)
False
b)
True
10.
myArray[0] + myArray[1] adds the first two values in an array together.
a)
True
b)
False
11.
Loops are useful for cycling through an array.
a)
True
b)
False
12.

Which of these is a list?

a)

fruit = ["apples", "oranges", "bananas"]

b)

fruit = "apples", "oranges", "bananas"

c)

fruit = {"apples", "oranges", "bananas"}

d)

fruit = ("apples", "oranges", "bananas")

13.
What is the position of the name 'Paula' in the following list:
names = ["Paul","Phillip","Paula","Phillipa"]
a)
0
b)
1
c)
2
d)
3
14.

In a list called "players", if you wanted to add a player called "Bob" to the list, which of the following examples of code would be correct in Python?

a)
players.add("Bob")
b)
player.append("Bob")
c)
players.append("Bob")
d)
players.addend("Bob")
15.

List items have an index number. In the following list, which item has the index number of 3?

["John", "Harry", "Jesse", "John", "Harry", "Harry"]

a)

"John"

b)

"Harry"

c)

"Jesse"

16.

How do i remove something from a list?

a)

variable.append()

b)

variable.delete()

c)

variable.remove()

d)

variable=(new variable)

17.

What does the '#' allow you to do?

a)

Repeat code

b)

Comment on code

c)

Print code

d)

End code

18.

An empty list can be declared as

a)

fruitList = ""

b)

fruitList = ["empty"]

c)

fruitList == []

d)

fruitList = []

19.

In programming, what is iteration?

a)

The repetition of steps within a program

b)

The order in which instructions are carried out

c)

A decision point in a program

d)

Testing a program to make sure it works

20.
Why is iteration important?
a)
It determines the order in which instructions are carried out
b)
It allows code to be simplified by removing duplicated steps
c)
It allows multiple paths through a program
d)
It ensures the code works correctly
21.
Which two statements are used to implement iteration?
a)
IF and WHILE
b)
ELSE and WHILE
c)
FOR and WHILE
d)
IF and ELSE
22.

FOR loops are

a)

loops which run an unknown number of times

b)

loops which run for a specific number of times

c)

the same as if statements

d)

not part of programming

23.

What does the following program display?

a)

1,2,3,4

b)

1,2,3,4,5

c)

counter,counter,counter,counter,counter

d)

0,1,2,3,4,5

24.
a)
b)
c)
d)

1,2,3,4

25.

When do you know when you come to the end of the loop?

a)

Its states End loop

b)

The command End is given

c)

The indentation stops

26.

if you wished a loop to repeat 3 types whwt should you use?

a)

For counter in range(0,5):

b)

For counter in range(1.3):

c)

For counter in range(0.3):

27.

what is the name of the variable used in the following code?

a)

counter

b)

print

c)

for

d)

#

28.

What is the purpose of a function?

a)

They are reusable pieces of programs.

b)

They are required by the Python

c)

They allow us to compile our program

d)

They make the program larger

29.

Which keyword is used for functions?

a)

func

b)

def

c)

define

d)

function

30.
What will print?
a)
nothing
b)
5
c)
6
d)
an error message
31.
What will print?
a)
nothing
b)
5
c)
6
d)
an error message
32.
How many times will Boo print?
a)
none
b)
4
c)
5
d)
1
33.
What will print?
a)
1 2
b)
1
c)
3
d)
5
34.

What term is used to describe data passed into a function?

a)

Variable

b)

Loop

c)

Constant

d)

Parameter

35.

Leo wants to create a function that will roll a dice. Which is the correct function definition header?

a)

def dice roll ():

b)

def diceroll ()

c)

def diceroll ():

d)

def diceroll []: