Question-2
python
GATE-2019(modified)
Control Flow
Consider the following Python program:
The number of times the variable sum_value will be printed when the above program is executed is ________
NoteAnswer
\(5\)
NoteSolution
The variable sum_value will be printed 5 times when the program is executed. This is because the program uses a while loop, and the condition i / j > 0.0625 is checked in each iteration. The loop continues until this condition becomes false. Analyzing the values of i and j in each iteration, we can see that it is printed in the first 5 iterations:
j = 1.0,i/j = 2.0/1.0 > 0.0625(True, Printed)j = 2.0,i/j = 2.0/2.0 > 0.0625(True, Printed)j = 4.0,i/j = 2.0/4.0 > 0.0625(True, Printed)j = 8.0,i/j = 2.0/8.0 > 0.0625(True, Printed)j = 16.0,i/j = 2.0/16.0 > 0.0625(True, Printed)