?
What will be the output of the following Python code?
What will be the output of the following Python code?
i = 1
while True:
if i%3 == 0:
break
print(i)
i + = 1
i = 1
while True:
if i%3 == 0:
break
print(i)
i + = 1
Answer & Solution
Correct Answer:
Option
B
Explanation:
The code starts with `i` initialized to 1.
The `while True` loop runs indefinitely until a `break` statement is encountered.
Inside the loop, the `if i%3 == 0:` condition checks if `i` is divisible by 3.
If `i` is divisible by 3, the `break` statement will terminate the loop.
If `i` is not divisible by 3, the value of `i` is printed.
Then, there's an error `i += 1` it should be not `i + = 1`.
So the correct answer is Option B: error
The code starts with `i` initialized to 1.
The `while True` loop runs indefinitely until a `break` statement is encountered.
Inside the loop, the `if i%3 == 0:` condition checks if `i` is divisible by 3.
If `i` is divisible by 3, the `break` statement will terminate the loop.
If `i` is not divisible by 3, the value of `i` is printed.
Then, there's an error `i += 1` it should be not `i + = 1`.
So the correct answer is Option B: error
Join the Discussion
Login to post a comment or share your explanation.
Logini have also tried running this code
i=1
while True:
if(i%3==0):
break
print(i)
i+=1