Skip to content
Exercises · Q5

Q.Find the output of the following program segments:

(i)
a = 110
while a > 100:
print(a)
a -= 2
(ii)
for i in range(20,30,2):
print(i)
(iii)
country = 'INDIA'
for i in country:
print
(i)
(iv)
i = 0; sum = 0
while i < 9:
if i % 4 == 0:
sum = sum + i
i = i + 2
print (sum)
(v)
for x in range(1,4):
for y in range(2,5):
if x * y > 10:
break
print (x * y)
(vi)
var = 7
while var > 0:
print ('Current variable value: ', var)
var = var -1
if var == 3:
break
else:
if var == 6:
var = var -1
continue
print ("Good bye!")
Yanam BieapTextbookSubjective· 4mImportance★★★★★est
72% · 28/39 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

Tracing each segment step by step: (i) 110→102 in steps of −2,

(ii) 20→28 in steps of 2,

(iii) I N D I A,

(iv) 12,

(v) 2 3 4 4 6 8 6 9,

(vi) prints values 7, 5, "Good bye!", 4 then breaks.

The reliable way to find a program's output is a dry run — track every variable, every test, every print, one step at a time.

(i) while a > 100, a starts at 110, a -= 2 each pass

Passa printeda after a -= 2a > 100?
1110108yes
2108106yes
3106104yes
4104102yes
5102100no → stop
110
108
106
104
102

(ii) for i in range(20, 30, 2) — start 20, stop 30 (excluded), step 2:

20
22
24
26
28

(iii) for i in country ("INDIA") — a string is a sequence of characters, so the loop prints each character:

I
N
D
I
A

(iv) while i < 9 with sum accumulating multiples of 4

i (start of pass)i % 4 == 0?sumi after i = i + 2
0yes02
2no04
4yes46
6no48
8yes1210 → loop ends
12

(v) nested loops with break when x * y > 10

xyx*yAction
122print 2
133print 3
144print 4
224print 4
236print 6
248print 8
326print 6
339print 9
341212 > 10 → break inner loop
2
3
4
4
6
8
6
9

(vi) while var > 0 with break/continue interplay

Passvar printedvar after −1var == 3?var == 6?Ends with
176noyes → var = 5, continue(no "Good bye!")

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.