Bird
0
0

What will be the output of this code?

medium📝 Predict Output Q4 of 15
Python - Basics and Execution Environment
What will be the output of this code?
for i in range(2):
    print('Loop', i)
    if i == 1:
        print('End')
ALoop 0 Loop 1 End
BLoop 0 End Loop 1
CLoop 0 Loop 1
DEnd Loop 0 Loop 1
Step-by-Step Solution
Solution:
  1. Step 1: Trace the for loop iterations

    The loop runs with i = 0 and then i = 1, printing 'Loop' and the value each time.
  2. Step 2: Check the if condition inside the loop

    When i equals 1, it prints 'End' after printing 'Loop 1'.
  3. Final Answer:

    Loop 0\nLoop 1\nEnd -> Option A
  4. Quick Check:

    Indentation controls when 'End' prints [OK]
Quick Trick: Indented if runs inside loop iteration [OK]
Common Mistakes:
MISTAKES
  • Ignoring indentation of if inside loop
  • Printing 'End' outside loop
  • Misordering output lines

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes