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
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Ā
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Ā
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Ā
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
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
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Ā
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
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
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Ā
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
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Ā
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?
Q.14 Which one of the following if statements will not execute successfully?
- if (1, 2) ;
print(‘foo’)
- if (1, 2) :
print(‘foo’)
- if (1) :
print( ‘foo’ )
- if (1) ;
print( ‘foo’ )
a) 1 ,4Ā
b) 2Ā
c) 2,4
d) 4
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Ā
Q.16 The ā¦ā¦ā¦ā¦ā¦ā¦ statement forms the selection construct in Python.
a) If else if
b..ifĀ
c. For ;Ā
d.for
Q.17 In Python, ā¦ā¦ā¦ā¦ā¦ā¦ā¦. defines a block of statements.
a. Block
b.loopĀ
c.indentationĀ
d.{}Ā
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
Q.19 Theā¦ā¦ā¦.. clause can occur with an if as well as with loops.
a) elseĀ
b. break
c. continue
d. none
Q.20 The ā¦ā¦ā¦ā¦.statement terminates the execution of the whole loop.
a) continue
b) exit
c. breake
d. breakĀ
| #TRENDING | |
Chapter-1 Basic Computer Organisation MCQsChapter-2 Types of Software, Operating System MCQsChapter-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
Q.22 An empty /null statement in Python is ā¦ā¦ā¦ā¦ā¦.
a) passĀ
b. noneĀ
c. null
d. none
Q.23 The break and continue statements, together are called ā¦ā¦ā¦ā¦ā¦.statement.
a) JumpĀ
b. gotoĀ
c. compound
d. none
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
Q.25 The two membership operators are ā¦ā¦ā¦.and ā¦ā¦ā¦ā¦
a) in, not inĀ
b. true , false
c.=,==
d. none
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Ā
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Ā
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
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
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Ā
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
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
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Ā
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
Q.35 Checking multiple conditions in python requires……….. statement
a) if
b. if……. elifĀ
c. switch
d. None of these
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Ā
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
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
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Ā
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
