Search the courses, subjects, tracks, games and features, or jump straight to a page.
3 cards from this section. Quick, good the night before a test.
What is the output of the following code?
for i in range(2):
for j in range(2):
print(i, j)Count how many times the inner loop runs for each iteration of the outer loop.
Write a simple nested loop to print a triangle of numbers with 3 rows.
The outer loop controls the rows, and the inner loop controls the columns.
What are nested loops?
Think about how you work with multi-dimensional data.
True or False: The inner loop runs completely for each iteration of the outer loop.
Consider what happens with the execution flow in a nested structure.
Write a function that takes a 2D list (matrix) and returns the sum of all its elements using nested loops.
You will need to initialize a total variable and use nested loops to iterate through each element.
Create a pattern output using nested loops to print a right-angled triangle. For size 5, it should look like:
*
**
***
****
*****The outer loop controls the rows, and the inner loop will control how many stars to print in each row.
5 more questions in this section. Enroll free to practise them all.
Enroll free