Complete the code to print "Done" after the while loop finishes normally.
count = 0 while count < 3: print(count) count += 1 else: print([1])
The else block runs after the while loop finishes normally. Printing the string "Done" shows this.
Complete the code to break the loop when count reaches 2.
count = 0 while count < 5: if count == [1]: break print(count) count += 1 else: print("Finished")
The loop breaks when count equals 2, so the else block will not run.
Fix the error in the else block to print "Loop ended" only if no break occurs.
i = 0 while i < 4: if i == 5: break print(i) i += 1 else: print([1])
The else block prints the string "Loop ended" only if the loop finishes without break. The string must be in quotes.
Fill both blanks to create a dictionary of squares for numbers less than 5, but only if the number is even.
squares = {x: x[1]2 for x in range(5) if x [2] 2 == 0}The expression x**2 calculates the square. The condition x % 2 == 0 checks if x is even.
Fill all three blanks to create a dictionary with uppercase keys and values greater than 1.
result = { [1]: [2] for k, v in data.items() if v [3] 1 }The key is converted to uppercase with k.upper(). The value v is used. The condition v > 1 filters values greater than 1.