WorksheetsProgramming Concepts Quiz
Total questions: 15
Worksheet time: 8mins
What is the main purpose of a for loop?
To make a decision based on a condition.
To repeat a block of code a specific number of times or for each item in a sequence.
To store a single piece of data.
To stop the program from running.
Which line of code correctly checks if a variable score is exactly 50?
if score = 50
if score > 50
if score == 50
if score != 50
What will len(['A', 'B', 'C']) return?
2
3
'C'
An error
How do you add a comment to a single line in a Python script?
``
/* This is a comment */
// This is a comment
# This is a comment
What is a Boolean value?
A number with a decimal point.
A whole number.
A sequence of characters.
A value that can only be True or False.
What is a 2D array?
A list that can only contain numbers.
A special type of variable for storing text.
A list where each item is another list, creating a grid-like structure.
A list that cannot be changed.
Using map = [[0, 1], [2, 3]], how would you access the number 1?
map[1][0]
map[0][1]
map[1][1]
map[0, 1]
In a nested loop for row in range(3): for col in range(3):, which variable changes the fastest?
row
col
They change at the same time.
range
What is the term for the first number used to access an element in a 2D array, like the 0 in grid[0][1]?
The column number
The element
The row index
The list index
If seating_plan = [['Amy', 'Ben'], ['Chloe', 'Dan'], ['Eva', 'Finn']], what is len(seating_plan)?
6
2
3
5
You have a 2D array scores where each inner list is [student_id, score]. How would you get the score of the first student?
scores[1][0]
scores[0][0]
scores[1]
scores[0][1]
You want to loop through a 10x8 grid called pixel_data (10 rows, 8 columns). What is the correct range for the loops?
for row in range(8): for col in range(10):
for row in range(9): for col in range(7):
for row in range(10): for col in range(8):
for row in range(11): for col in range(9):
Given grid = [[0, 0, 0], [0, 0, 0], [0, 0, 0]], what is the best way to set the entire first column to 1?
grid[0] = [1, 1, 1]
for i in range(3): grid[i][0] = 1
grid[1][0] = 1
grid[0][1] = 1
When processing a 2D array of sales data, why is a nested for loop a good structure to find the total sales?
Because it is the only way to access the elements.
Because it allows you to systematically visit every cell by iterating through each row and column.
Because it is faster than a single loop.
Because it uses less memory.
What is the purpose of initializing a variable like `total_points = 0` before starting a loop that calculates a team's score?
To make sure the variable is a number and not text.
To store the highest possible score a team can get.
To make the code easier to read without changing how it runs.
To create a clean starting point (an accumulator) that you can correctly add points to during each iteration of the loop.
