• +91 9971497814
  • info@interviewmaterial.com

Chapter 11- Conditional and Looping Constructs Interview Questions Answers

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.


Selected

 

Chapter 11- Conditional and Looping Constructs Contributors

krishan

Share your email for latest updates

Name:
Email:

Our partners