Complete the code to print numbers from 1 to 5 using a while loop.
count = 1 while [1]: print(count) count += 1
The condition count <= 5 keeps the loop running until count reaches 5.
Complete the code to keep asking the user for input until they type 'exit'.
user_input = '' while [1]: user_input = input('Type something (or exit): ') print('Goodbye!')
The loop continues while the input is not 'exit'. When the user types 'exit', the loop stops.
Fix the error in the code to avoid an infinite loop that prints numbers from 1 to 3.
num = 1 while num <= 3: print(num) [1]
Incrementing num by 1 ensures the loop will eventually stop when num becomes greater than 3.
Fill both blanks to create a dictionary of squares for numbers 1 to 5 using a while loop.
squares = {}
i = 1
while [1]:
squares[i] = i[2]2
i += 1The loop runs while i is less than or equal to 5. The exponent operator ** is used to square i.
Fill all three blanks to create a dictionary of words and their lengths for words longer than 3 letters.
words = ['apple', 'bat', 'carrot', 'dog'] lengths = { [1]: [2] for word in words if len(word) [3] 3 }
The dictionary uses the word as the key and its length as the value. The condition filters words longer than 3 letters using '>'.