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()0 00 10 20 0 0 0 1 2Infinite loopError

Question

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()0 00 10 20 0 0 0 1 2Infinite loopError

🧐 Not the exact question you are looking for?Go ask a question

Solution

The output of the given code will be an infinite loop. This is because the outer loop variable 'i' is not being incremented within the loop. As a result, the condition for the outer loop (i<3) will always be true, causing the loop to run indefinitely.

To fix this, you should increment 'i' within the outer loop. Here's how you can do it:

i=0
while(i<3):    
    j=0    
    while(j<3):        
        print(i,j,end=" ")        
        j+=1    
    print()
    i+=1

With this correction, the output will be:

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

This problem has been solved

Similar Questions

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

What will be the output of the following Python code?i = 1while True:    if i%3 == 0:        continue    print(i)    i+ =11 21 2 3errorNone of the mentioned

What will be the output of the following Python program?  i = 0while i < 5: print(i) i += 1 if i == 3: breakelse: print(0)error0 1 2 00 1 2none of the mentioned

1 pointWhat is the output of the following code?i = 2while True:    if i%3 == 0:        break    print(i)    i += 22 4 6 8 10 ...2 32 4Error

= 0while i < 5: if i == 2: i += 1 continue else: print(i,end = " ") i += 1Options: Pick one correct answer from below0 1 2 3 40 1 3 4Runtime Error1

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.