Knowee
Questions
Features
Study Tools

What will be the output for the following code?i=0while(i<3):    j=0    while(j<3):        print(i,j,end=" ")        j+=1    print()

Question

What will be the output for the following code?

i=0
while(i&lt;3):
    j=0
    while(j&lt;3):
        print(i,j,end=&quot; &quot;)
        j+=1
    print()
🧐 Not the exact question you are looking for?Go ask a question

Solution

The output of the given code will be:

0 0 0 1 0 2 1 0 1 1 1 2 2 0 2 1 2 2

Here's the step by step explanation:

  1. The outer loop runs three times as i ranges from 0 to 2.
  2. For each iteration of the outer loop, the inner loop also runs three times as j ranges from 0 to 2.
  3. In each iteration of the inner loop, the current values of i and j are printed, followed by a space.
  4. After each iteration of the outer loop, a newline is printed. This is why each set of three pairs is on a new line.

This problem has been solved

Similar Questions

Study the following program:i = 0while i < 3:       print(i)       i += 1 else:      print(0)

What will be the output of the following program?while i < 20: print(i) i += 1

What is the output of the following few lines of code?1234x=0while(x<2):    print(x)    x=x+1   1 point010120134

What is the output of the following code snippet?int i = 0;do {    if (i == 3)        continue;    System.out.print(i + " ");    i++;} while (i < 5);

What is the output of the following code? for i in range(3):   print(i) else:   print("Loop finished")

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.