Complete the code to print each number from 1 to 3.
for num in [1]: print(num)
The range(1, 4) function generates numbers 1, 2, and 3. The for loop prints each number.
Complete the code to sum all numbers from 1 to 5 using a for loop.
total = 0 for i in range(1, 6): total += [1] print(total)
Inside the loop, we add the current number i to total to get the sum.
Fix the error in the code to print each character in the string.
word = "hello" for [1] in word: print(letter)
The loop variable should be letter because it is used inside the loop to print each character.
Fill both blanks to create a dictionary with words as keys and their lengths as values for words longer than 3 letters.
lengths = { [1]: [2] for word in words if len(word) > 3 }word.upper() as the key.len without calling it.The dictionary keys are the words themselves, and the values are their lengths using len(word).
Fill all three blanks to create a dictionary with uppercase words as keys, their lengths as values, only for words longer than 4 letters.
result = { [1]: [2] for word in words if [3] }len(word) in the condition.The keys are uppercase words using word.upper(), values are their lengths, and the condition filters words longer than 4 letters.