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 + = 1A. 1 2 3
B. error
C. 1 2
D. none of the mentioned
Answer: Option B
Solution (By Examveda Team)
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
Join The Discussion
Comments (2)
Related Questions on Introduction to Python
What is Python primarily used for?
A. Web browsing
B. Data analysis
C. Video editing
D. Game development
Who developed Python Programming Language?
A. Wick van Rossum
B. Rasmus Lerdorf
C. Guido van Rossum
D. Niene Stom
Which of the following is an advantage of Python?
A. It compiles to machine code
B. It enforces strict typing
C. It has a large standard library
D. It requires extensive memory management
What is the role of the Python interpreter?
A. To convert Python code to assembly language
B. To manage memory allocation
C. To execute Python code line by line
D. To compile Python code into bytecode

answer is correct there is error in code , bcz it has a space in between + and =, whis is not allowed
as per me the answere should be C
i have also tried running this code
i=1
while True:
if(i%3==0):
break
print(i)
i+=1