• +91 9971497814
• info@interviewmaterial.com

# Chapter 11- Conditional and Looping Constructs Interview Questions Answers

### Related Subjects

Question 1 :
Why do we use ‘break’ statement ?

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

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

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

True

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

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

Question 7 :
Write the syntax of an ’if statement1 in Python programming language

if expression :
statement(s)

Question 8 :
Write the syntax of an if…..else statement in Python programming language

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!

Value of expression is 100
Good bye

Question 10 :
Define while loops.

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

krishan