Q. Is the loop in the code below infinite? How do you know (for sure) before you run it?


m = 3

n = 5

while n < 10 :

    m = n - 1

    n = 2 * n - m

    print(n, m)


Answer :-


This program executes finite because while loop has the condition (n<10). So when n becomes greater than 10 then the program break.


Output :-


6 4
7 5
8 6
9 7
10 8

>>> 

4 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. answer is below, might be helpful for others
    6 4
    7 5
    8 6
    9 7
    10 8

    ReplyDelete
  2. How you can access n value as 6? At the end of the programme n+=1 is not written.

    ReplyDelete
    Replies
    1. value of n is changing due to n = 2 * n - m statement.

      Delete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post