πŸ“Š Python
Q. What is the output of the following program :
Code:
i = 0
while i < 5:
    print(i)
    i += 1
    if i == 3:
        break
else:
    print(0)
  • (A) 0 1 2 0
  • (B) 0 1 2
  • (C) Error
  • (D) None of the above
πŸ’¬ Discuss
βœ… Correct Answer: (B) 0 1 2

Explanation: In the code above, i is initialise with 0. While loop runs till the value of i is reached to 5. But when I==3 there is break; so while loop will end.

Output will be 0 1 2.

Explanation by: Mr. Dubey
In the code above, i is initialise with 0. While loop runs till the value of i is reached to 5. But when I==3 there is break; so while loop will end.

Output will be 0 1 2.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
311
Total Visits
πŸ“½οΈ
4 y ago
Published
πŸŽ–οΈ
Ram Sharma
Publisher
πŸ“ˆ
89%
Success Rate