MCQs on Flow of control, conditional statements

Topic: OUTPUT,ERRORS,FLOW OF CONTROL,CONDITIONAL STATEMENTS




 

Q.1 Which one of the following is a valid Python if statement :

a) if a>=2 : 

b) if (a >= 2)

c) if (a => 22)

d) if a >= 22

a) if a>=2 : 

 

 

Q.2 Which of following is not a decision-making statement.

a) if-elif statement

b. for statement 

c. if -else statement

d. if statement 

b. for statement 

 

 

Q.3 What does the following code print to console.

if True:

print(1001)

else:

print(2002)

 





a) 1001 

b.true

c.2002

d. false 

a) 1001 

 

 

Q.4 What will be the output of the following Python code?

list1 = [3 , 2 , 5 , 6 , 0 , 7, 9]

sum = 0

sum1 = 0

for elem in list1:

if (elem % 2 == 0):

sum = sum + elem

continue

if (elem % 3 == 0):

sum1 = sum1 + elem

print(sum , end=” “)

print(sum1)

a. 8 9 

b. 8 3

c. 2 3

d. 8 12 

d. 8 12 

 

 

Q.5 What will be the output of the following Python code?

If 4+5==10:

print(“TRUE”)

else:

print(“false”)

print (“True”)

a. False

True

b. True 

True

c. false 

d. none

b. True 

True

  

 

 

Q.6 What keyword would you use to add an alternative condition to an if statement?

a. else if

b. elseif

c. elif 

d. None of the above

c. elif 

 

 

Q.7 What will be the output of the following Python code?

str1=”learn python”

str2=””

str3=””

for x in str1:

if(x==”r” or x==”n” or x==”p”):

str2+=x

pass

if(x==”r” or x==”e” or x==”a”):

str3+=x

print(str2,end=” “)

print(str3)

a) rnpn ea

b) rnpn ear 

c) rnp ea

d) rnp ear 

b) rnpn ear 

 

 

Q.8 Predict the output of the following code:

X=3

If x>2 or x<5 and x==6:

Print(“ok”)

else:

print(“no output”)

a . ok

b. okok 

c. no output 

d. none of above

c. no output 

 

 

Q.9 Predict the output of the following code:

x,y=2,4

if(x+y= =10):

print(“true”)

else:

print(“false”)

a. true

b .false 

c. no output

d. none

b) False 

 

 

Q.10 Consider the following code segment:

a = int(input(“Enter an integer: “))

b = int(input(“Enter an integer: “))

if a <= 0:

b = b +1

else:

a = a + 1

if a > 0 and b > 0:

print (“W”)

elif a > 0:

print(“X”)

if b > 0:

print(“Y”)

else:

print(“Z”)

What letters will be printed if the user enters -1 for a and -1 for b?

a) Only W

b. Only X 

c. Only Y

d. Only Z 

d. Only Z 

 

 

Q.11 If the user inputs : 2<ENTER>, what does the following code snippet print?

x = float(input())

if(x==1):

print(“Yes”)

elif (x >= 2):

print(“Maybe”)

else:

print (“No”)

a.Yes

b.No 

c.Maybe 

d.Nothing is printed

c.Maybe 

 

 

Q.12 What will be the output of given Python code?

str1=”hello”

c=0

for x in str1:

if(x!=”l”):

c=c+1

else:

pass

print(c)

a) 2

b. 0

c. 4

d. 3 

d. 3 

 

 

Q.13 What does the following Python program display ?

x = 3

if x == 0:

print (“Am I here?”, end = ‘ ‘)

elif x == 3:

print(“Or here?”, end = ‘ ‘)

else :

pass

print (“Or over here?”)

a) Am I here?

b. Or here? 

c.Am I here? Or here?

d.Or here ? 

Or over here?

d) Or here ? 

Or over here?

 

Q.14 Which one of the following if statements will not execute successfully?

  1. if (1, 2) ;

print(‘foo’)

  1. if (1, 2) :

print(‘foo’)

  1. if (1) :

print( ‘foo’ )

  1. if (1) ;

print( ‘foo’ )

a) 1 ,4 

b) 2 

c) 2,4

d) 4

b) 2 

 

 

Q.15 if( a):

print(“a is non zero”)

else:

print(“its results is True”)

a) false 

b)  True

c)  Its result is True

d)  a is nonzero 

d)  a is nonzero 

 

 

Q.16 The ……………… statement forms the selection construct in Python.

a) If else if

b..if 

c. For ; 

d.for

b) if 

 

 

Q.17 In Python, …………………. defines a block of statements.

a. Block

b.loop 

c.indentation 

d.{} 

c. indentation

 

 

Q.18 An ……………… statement has less number of conditional checks than two successive ifs.

a) If else if

b. if elif 

c. if-else 

d. none

c. if-else 

 

 

Q.19 The……….. clause can occur with an if as well as with loops.

a) else 

b. break

c. continue

d. none

a) else 

 

 

Q.20 The ………….statement terminates the execution of the whole loop.

a) continue

b) exit

c. breake

d. break 

d. break 

 

 

#TRENDING

Chapter-1 Basic Computer Organisation MCQs

Chapter-2 Types of Software, Operating System MCQs

Chapter-3 Boolean Algebra, Number System MCQs

 

 

Q.21 The ……….. operator tests if a given value is contained in a sequence or not.

a) In:

b) in 

c. not in

d. none

b) in 

 

 

Q.22 An empty /null statement in Python is …………….

a) pass 

b. none 

c. null

d. none

a) pass 

 

 

Q.23 The break and continue statements, together are called …………….statement.

a) Jump 

b. goto 

c. compound

d. none

b. goto 

 

 

Q.24 The order of statement execution in the form of top to bottom is known as construct.

a) alternate

b.sequence 

c.flow of data

d. flow chart

b.sequence 

 

 

Q.25 The two membership operators are ……….and …………

a) in, not in 

b. true , false

c.=,==

d. none

a) in, not in 

 

 

Q.26 A graphical representation of an algorithm to solve a problem is called ……………

a) flow of data

b. barchart

c. flow chart 

d. none 

c. flow chart 

 

 

Q.27 What is the logical expression for the following

Either A is greater than B or A is less than C

a) A>B or A<C 

b. A>B and A<C

c . A>Band C

d. A>B or C 

a) A>B or A<C 

 

 

Q.28 Name is rohit and age between 18 and 35

a) name==rohit and age >=18 and age<=35 

b) name==rohit and age >=18 or age<=35

c) name==rohit or age >=18 and age<=35 

d) none

c) name==rohit or age >=18 and age<=35 

 

 

Q.29 Donation in the range of4000-5000 or guest=1

a) (donation>=4000 and donation<=5000) or guest==1 

b) donation>=4000 or donation<=5000 or guest==1

c) donation>=4000 and (donation<=5000 or guest==1) 

d) donation>=4000 and donation<=5000) or guest==1

a) (donation>=4000 and donation<=5000) or guest==1 

 

 

Q.30 State which of the following statement are true .

1.If,elif ,else are not compound statement.

2.Else if can be used in python.

3.Indentation while working with blocks is not necessary in python.

4.A pass statement is a null operation;it does nothing.

a.1

b.2 ,3

c.3

d.4 

d.4 

 

 

Q.31 In a Python program, a control structure:

a) Defines program-specific data structures 

b) Directs the order of execution of the statements in the program 

c) Dictates what happens before the program starts and after it terminates

d) None of the above

b) Directs the order of execution of the statements in the program 

 

 

Q.32 Does python have switch case statement?

a) True

b) False 

c) Python has switch statement but we can not use it.

d) None of the above

b) False 

 

 

Q.33 What will be output of this expression:

‘p’ + ‘q’ if ’12’.isdigit() else ‘r’ + ‘s’

a) pq

b. rs 

c. pqrs

d. pq12 

b. rs 

 

 

Q.34 Which statement will check if a is equal to b?

a) if a == b: 

b. if a = b:

c. if a === c: 

d. if a == b

a) if a == b: 

 

 

Q.35 Checking multiple conditions in python requires……….. statement

a) if

b. if……. elif 

c. switch

d. None of these

b. if……. elif

 

 

Q.36 if the condition is …………. , the statements of if block will be executed otherwise the statements in the ……….. block will be executed

a) false, true

b. true, else 

c. both options are true

d.Can’t say 

b) true, else

 

 

Q.37 What will be output after execution of the following code?

a=11

B=5 

If(a//b==2):

Print (“Yes”)

else :

Print(“No”)

a) 2.5

b)Yes 

c)No

d)21

b) Yes  

 

 

Q.38 What will be output after execution of the following code?

a=11

b=5

if (a%b==0):

print ( “Greater”)

if (a//b==0):

print ( “Example”)

else

print (“Sooo Sorry”)

a) Sooo Sorry

b)Great 

c)Example 

d)Great Example

b) Great 

 

 

Q.39 . What will be the output of the following program if we input 8

Ch= int (“Enter Day of week (1 to 7 “))

If ch==1:

print (“Monday”)

elif ch==2:

print (“Tuesday”)

elif ch==3:

print (“Wednesday”)

elif ch==4:

Page 38 of 55

print (“Thursday”)

elif ch==5:

print (“Friday”)

elif ch==6:

print (“Saturday”)

else:

print (“Sunday”)

a) Sunday 

b)Monday

c)All days will be printed

d)No Output 

d)No Output 

 

 

Q.40 Mala wants to make a fun program , if user enters any number a Good or funny message will appear . She is confused that which is the most suitable control to be used to make such program. Help her to choose correct option.

a) If

b.if else 

c.if elif 

d.Nested if else

b) if else 

 

Copywrite © 2020-2024, CBSE Python,
All Rights Reserved