Complete the code to print "Found" if 3 is in the list, otherwise print "Not found".
numbers = [1, 2, 3, 4, 5] for num in numbers: if num == [1]: print("Found") break else: print("Not found")
The loop checks each number. When it finds 3, it prints "Found" and stops. The else runs only if the loop never breaks.
Complete the code to print "No even number" if no even number is found in the list.
nums = [1, 3, 5, 7] for n in nums: if n % [1] == 0: print("Even number found") break else: print("No even number")
Even numbers are divisible by 2. The code checks if any number is divisible by 2. If none are, the else block runs.
Fix the error in the code to correctly print "Found" if 0 is in the list, else "Not found".
values = [1, 2, 3, 4] for val in values: if val == [1]: print("Found") break else: print("Not found")
The code looks for 0, but 0 is not in the list. Fixing the value to 0 makes the condition correct for the task.
Fill both blanks to create a dictionary of squares for numbers greater than 2.
squares = {x: x[1]2 for x in range(1, 6) if x [2] 2}
print(squares)The code uses exponentiation (**) to square numbers. The condition x > 2 filters numbers greater than 2.
Fill all three blanks to create a dictionary of uppercase keys and values greater than 1.
result = [1]: [2] for k, v in data.items() if v [3] 1 print(result)
The keys are converted to uppercase with k.upper(). Values are kept as v. The condition filters values greater than 1.