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
>>>
7 5
8 6
9 7
10 8
>>>
answer is below, might be helpful for others
ReplyDelete6 4
7 5
8 6
9 7
10 8
: )
DeleteHow you can access n value as 6? At the end of the programme n+=1 is not written.
ReplyDeletevalue of n is changing due to n = 2 * n - m statement.
DeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )