What will be printed by the following code?
for i in range(3): print(i * 2)
Remember, range(3) produces 0, 1, 2.
The loop runs with i = 0, 1, 2. Multiplying each by 2 gives 0, 2, 4.
What will happen when this code runs?
count = 3 while count > 0: print(count) count -= 1
Check the condition count > 0 and how count changes.
The loop prints 3, then 2, then 1. When count becomes 0, the condition fails and loop stops.
Which option correctly describes the difference between these two loops?
Loop 1:
for i in range(1, 5):
print(i)
Loop 2:
i = 1
while i < 5:
print(i)
i += 1Check the range and condition carefully.
Both loops print numbers 1 to 4. Loop 1 uses for, Loop 2 uses while but output is same.
What error will this code cause?
i = 0 while i < 3: print(i) i += 1
Check the indentation of lines inside the loop.
Python requires code inside loops to be indented. Here print and i += 1 are not indented, causing IndentationError.
What is the final value of total after running this code?
total = 0
for x in range(3):
for y in range(2):
total += x + yCalculate sums for each pair (x, y) and add carefully.
Pairs and sums: (0+0)=0, (0+1)=1, (1+0)=1, (1+1)=2, (2+0)=2, (2+1)=3. Sum = 0+1+1+2+2+3 = 9.