12. Nested loops
A nested loop is a loop inside another loop. The outer loop runs once for each of its elements, and for each of those passes the inner loop runs completely.
The output is A 1, A 2, B 1, B 2: the inner loop finishes before the outer loop moves to its next element.
Indent the inner loop one more level (eight spaces in total). The inner loop can use names from the outer loop, such as letter above.
Combine two lists
Use letters = ["A", "B"] and numbers = [1, 2]. Write a nested loop and print each combination as A1 using an f-string.
Print exactly:
Create a free account to save your progress and unlock chapter 2.
Draw a grid of stars
Use an outer for over range(2) and an inner for over range(3). Print * with end="" in the inner loop, and call print() once after the inner loop to end each row.
Print exactly:
Create a free account to save your progress and unlock chapter 2.
Build a multiplication table
Use two nested loops over range(1, 4) and print every pair as a x b = product using an f-string.
Print exactly:
Create a free account to save your progress and unlock chapter 2.