MENU

Chapter 11 Conditional and Looping Constructs Solutions

Question - 1 : -
Why do we use тАШbreakтАЩ statement ?

Answer - 1 : -

The тАШbreakтАЩ statement can be used to terminate the loop.

Question - 2 : -
What gets printed with the following code ?
x = True
y = False
z = False
if x or y and z :
print тАЬyesтАЭ
else:
print тАЬno

Answer - 2 : -

Yes

Question - 3 : -
What gets printed with the following code ?
x = True
y = False
z = False
if not x or y :
print 1
elif not x or not y and z:
print 2
elif not x or y or not y and x:
print 3
else:
print 4

Answer - 3 : - 3

Question - 4 : -
What gets printed with given code ?
f = None
for i in range (5):
with open(тАЬdata.txtтАЭ, тАЬwтАЭ) as f:
if i > 2:
break
print f.closed

Answer - 4 : -

True

Question - 5 : -
Which numbers are printed?
for i in range(2):
print i
for i in range(4,6):
print i

Answer - 5 : -

0,1,4, 5

Question - 6 : -
What gets printed?
import re
sum = 0
pattern = тАШbackтАЩ
if re.match(pattern, тАШbackup.txtтАЩ):
sum + = 1
if re.match(pattern, тАШtext.backтАЩ):
sum + = 2
if re.search(pattern, тАШbackup.txtтАЩ):
sum + = 4
if re.search(pattern, тАШtext.backтАЩ):
sum + = 8
print sum

Answer - 6 : - 13

Question - 7 : -
Write the syntax of an тАЩif statement1 in Python programming language

Answer - 7 : -

if expression :
statement(s)

Question - 8 : -
Write the syntax of an ifтАж..else statement in Python programming language

Answer - 8 : -

if expression:
statement(s)
else:
statement(s)

Question - 9 : -
Write the output
#!/usr/bin/python
var =100
if(var==100):
print тАЬValue of expression is 100тАЭ
print тАЬGood bye!

Answer - 9 : -

Value of expression is 100
Good bye

Question - 10 : -
Define while loops.

Answer - 10 : -

A while loop statement in Python programming language repeatedly executes a target statement as long as a given condition is true.

Free - Previous Years Question Papers
Any questions? Ask us!
×