Computer Science, asked by Swayamjeet09, 6 months ago

What will be the output produced when this code executes. (2)

a=0

for i in range(4,8):

if i%2==0:

a=a+i

print(a)​

Answers

Answered by anindyaadhikari13
20

Question:-

Write the output of the following code.

Working out:-

Given code,

a=0

for i in range(4,8):

if i%2==0:

a=a+i

print(a)

At first, i=4

4%2==0 is True

So,

a=a+i

Or,

a=0+4=4

Now,

i=5

5%2==0 is False

Then,

i=6

6%2==0 is True

So,

a=a+i

Or,

a=4+6

Or,

a=10

After next iteration,

i=7

7%2==0 is False

So, if block will not execute and the loop terminates.

Finally, a is printed.

Output:-

10

Similar questions