🚀 Hurry! Offer Ends In
00 Days
00 Hours
00 Mins
00 Secs
Enroll Now
X

निम्नलिखित का आउटपुट क्या है?

What is the output of the following ?

i = 2
while True:
    if i%3 == 0:
        break
    print(i,end=" " )
    i += 2
A)
B)
C)
D)

Explanation:

Let's break down the code:

i = 2
while True:
    if i % 3 == 0:
        break
    print(i, end=" ")
    i += 2

Step-by-step execution:

  1. i = 2: We start with i = 2.

  2. First iteration:

    • i % 3 == 0 is False because 2 % 3 == 2.
    • print(i, end=" ") prints 2.
    • i += 2 makes i = 4.
  3. Second iteration:

    • i = 4, so i % 3 == 0 is still False because 4 % 3 == 1.
    • print(i, end=" ") prints 4.
    • i += 2 makes i = 6.
  4. Third iteration:

    • i = 6, so i % 3 == 0 is True because 6 % 3 == 0.
    • The break statement is executed, and the loop stops.

Conclusion:

The output is 2 4.

Answer:

(B) 2 4

Latest Updates