CBSE Class 11 Computer Science Question 116 of 161

Flow of Control — Question 25

Back to all questions
25
Question

Question 11k

Predict the output of the following code fragments:

x = 10                     
y = 5                     
for i in range(x-y * 2):  
    print (" % ", i)

Answer

This code generates No Output.

Explanation

The x-y * 2 in range(x-y * 2) is evaluated as below:

    x - y * 2
⇒ 10 - 5 * 2
⇒ 10 - 10 [∵ * has higher precedence than -]
⇒ 0

Thus range(x-y * 2) is equivalent to range(0) which returns an empty sequence — [ ].

Answer