Complete the code to print numbers from 1 to 5 using a loop.
for i in range(1, [1]): print(i)
The range function stops before the end number, so to print 1 to 5, we use range(1, 6).
Complete the code to sum numbers from 1 to 4 using a loop.
total = 0 for num in range(1, [1]): total += num print(total)
To sum numbers 1 to 4, the loop must run from 1 to 5 (exclusive), so range(1, 5).
Fix the error in the loop to print each character in the word.
word = 'hello' for [1] in word: print(letter)
The loop variable should be letter to match the print statement.
Fill both blanks to create a dictionary of squares for numbers 1 to 5.
squares = {x: x[1]2 for x in range(1, [2])}+ instead of exponentiation.Use ** for exponentiation and 6 as the range end to include 5.
Fill all three blanks to create a dictionary of uppercase words with their lengths, filtering words longer than 3 letters.
result = [1]: [2] for word in words if len(word) [3] 3}
word instead of uppercase for keys.< or == instead of > in the condition.The key is the uppercase word, the value is its length, and the condition filters words longer than 3 letters.