Computer Science, asked by primce12345678, 2 months ago

Consider the following code segment:

for i in range(2,4):

    print (i)

What value(s) are printed when it executes ? 

Answers

Answered by BrainlyProgrammer
1

OUTPUT:-

2

3

Explanation:

By default, in python the value of I increses by 1.

Given initial value of I is 2 and the limit is 4.

Note:-

Here the loop will start from 2 and will work upto 3 that is...4 is not included in it

Therefore

  1. When I is 2, Output will be 2 and the cursor will got to the next line and the value of I increases.
  2. When the value increases the control checks if the value of I is less then 4...True....it will print 3.....Now the value of I is 4
  3. 4<4 ... Condition False....So loop will terminate

Therefore,

The correct output is:-

2

3

Similar questions