1.

What is the output of the following snippet? i=1while True:if i%3 ==0:breakprint(i,end=")i +=1​

Answer»

1 2Explanation:Check the attachment given below. Language: Python.As a is initially assigned with 1,In "while TRUE:", as the CONDITION is always True, the only way to terminate it is to use unconditional statements (as break in if statement)When i=1, the if condition 1%3==0 becomes false and 1 is PRINTED, while i gets incremented.Similarly, When i=2, the if condition 2%3==0 becomes false and 2 is printed, while i gets incremented.But, when i=3, the if condition 3%3==0 becomes true and break statement gets executed, resulting in the termination of loop.So, the output is 1 2



Discussion

No Comment Found