wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

J277 - 2.2 - Use of Arrays up to 2D

Total questions: 8

Worksheet time: 4mins

Name
Class
Date
1.

What is an array in programming?

a)

A data structure that stores elements in a key-value pair format.

b)

A data structure that stores a collection of elements, typically of the same data type, in a contiguous memory location.

c)

A function that performs operations on a set of numbers.

d)

A loop that iterates over a sequence of numbers.

2.

Which of the following is a valid way to declare a one-dimensional array in Python?

a)

`array = [1, 2, 3, 4]`

b)

`array = (1, 2, 3, 4)`

c)

`array = {1, 2, 3, 4}`

d)

`array = <1, 2, 3, 4>`

3.

How do you access the third element in a one-dimensional array named `numbers` in Python?

a)

`numbers[2]`

b)

`numbers[3]`

c)

`numbers[1]`

d)

`numbers[0]`

4.

What is the result of the following operation on a 1D array `arr = [5, 10, 15, 20]`: `arr[1] = 25`?

a)

`[5, 10, 15, 20]`

b)

`[5, 25, 15, 20]`

c)

`[5, 10, 25, 20]`

d)

`[25, 10, 15, 20]`

5.

Which of the following best describes a two-dimensional array?

a)

A list of lists where each element is a list.

b)

A single list with multiple data types.

c)

A dictionary with keys and values.

d)

A set of unique elements.

6.

How do you access the element in the second row and third column of a 2D array `matrix` in Python?

a)

`matrix[1][2]`

b)

`matrix[2][3]`

c)

`matrix[3][2]`

d)

`matrix[2][1]`

7.

What is the result of the following operation on a 2D array `matrix = [[1, 2], [3, 4]]`: `matrix[0][1] = 5`?

a)

`[[1, 2], [3, 4]]`

b)

`[[1, 5], [3, 4]]`

c)

`[[5, 2], [3, 4]]`

d)

`[[1, 2], [5, 4]]`

8.

In a 2D array, how would you describe the operation of iterating over each element in the array?

a)

Nested loops where the outer loop iterates over rows and the inner loop iterates over columns.

b)

A single loop iterating over all elements.

c)

A recursive function call.

d)

A function that returns the length of the array.