Complete the code to print numbers from 1 to 3 using a for loop.
for i in [1]: print(i)
The range(1, 4) function generates numbers 1, 2, and 3, which the loop prints.
Complete the code to print all pairs of numbers from 1 to 2 using nested loops.
for i in range(1, 3): for j in [1]: print(i, j)
The inner loop uses range(1, 3) to match the outer loop's range, printing pairs (1,1), (1,2), (2,1), and (2,2).
Fix the error in the nested loop to print all pairs of letters and numbers.
letters = ['a', 'b'] numbers = [1, 2] for letter in letters: for num in [1]: print(letter, num)
letter inside the inner loop.letters again.The inner loop should iterate over the numbers list to pair each letter with each number.
Fill both blanks to create a nested loop that prints all combinations of colors and sizes.
colors = ['red', 'blue'] sizes = ['S', 'M'] for [1] in colors: for [2] in sizes: print(color, size)
item or value that don't match the print statement.The outer loop variable is color and the inner loop variable is size to match the lists and print correctly.
Fill all three blanks to create a nested loop that builds a dictionary with keys as colors and values as sizes.
colors = ['red', 'green'] sizes = ['L', 'XL'] combo_dict = {} for [1] in colors: for [2] in sizes: combo_dict[[3]] = size print(combo_dict)
The outer loop variable is color, the inner loop variable is size, and the dictionary key is color to store the last size for each color.