Question #355

What is the output of the code snippet below?
number = 28
for num in range(25, 30):
    if number > num:
        print(num)
    else:
        print(num)
        break

Here, the Python control reaches line 4 three times and line 6 one time. During the iteration of the for loop in line 2, when values of num are 25, 26 and 27 (i.e. values smaller than 28), the control is reaching line 4 and when num is 28, it is reaching line 6 before breaking out from the loop. (w3schools.com/python/ref_func_range.asp)


Comment on Disqus:

Question difficulty: ๐Ÿ”ต๐Ÿ”ต๐Ÿ”ต๐Ÿ”ต๐Ÿ”ต