Knowee
Questions
Features
Study Tools

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

Question

What will be the output of the following program?

while i &lt; 20:
    print(i)
    i += 1
🧐 Not the exact question you are looking for?Go ask a question

Solution

The program will result in an error because the variable 'i' is not defined before the while loop.

However, if we assume that 'i' is defined and its initial value is 0, then the program will print numbers from 0 to 19. Each number will be printed on a new line. The loop will stop when 'i' becomes 20 because 20 is not less than 20.

Here is the corrected code:

i = 0
while i < 20:
  print(i)
  i += 1

And here is the output:

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

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 for the following code?i=0while(i<3):    j=0    while(j<3):        print(i,j,end=" ")        j+=1    print()

What is the output of the following piece of code?int i;i = 10;while (i < 20){ printf("%d", i % 2); i++;}

What will be the result?1. int i = 10;2. while(i++ <= 10){3. i++;4. }5. System.out.print(i);10111213

What will be the output of the following code?          int i = 1;while(i<10){  if (i / 2 == 2)     cout << i << “ ”;i++;}

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.