aInfoEra
Home
MCQs
Python — Quiz
MCQ on Flow of Control in PythonSet 2
72 questions · Test your knowledge
Home
/
MCQs
/
MCQ on Flow of Control in PythonSet 2
1
Which of the following is not a conditional statement in Python?
A
if statement
B
if – else statement
C
if – elif statement
D
None of the above
2
Which of the following symbol is used to end an ‘if’ statement in Python?
A
Comma( , )
B
Colon( : )
C
Semi Colon( ; )
D
None of the above
3
Write the output of the following : x = 10 if x > 7 and x <= 10: print("Pass", end="") print("Fail")
A
Pass
B
Fail
C
Pass Fail
D
PassFail
4
Which of the following value of ‘x’ makes the condition False in the given code?
A
8
B
9
C
5
D
33
5
Write the output of the following : if 'i' == "i" : print(True) else: print("False")
A
True
B
False
C
Error
D
None of the above
6
Write the output of the following: if (3+8//2 != 7): print("H") else: print("B")
A
H
B
B
C
Error
D
None of the above
7
Write the output of the following: a=5 b=6 c=7 d=8 if a > b: if c > a: if d < c: print("Hello") else: print("B") else: print("A") print("What")
A
What
B
Hello
C
B
D
A
8
Write the output of the following: a=15 b=6 c=7 d=8 if a > b: if c > a: if d < c: print("Hello") else: print("B") else: print("A")
A
Error
B
Hello
C
B
D
A
9
Repetition of a set of statements in a program is made possible using _____
A
Selection Constructs
B
Sequential Constructs
C
Looping Constructs
D
None of the above
10
The statements in a loop are executed repeatedly as long as particular condition ___
A
remains False
B
remains True
C
gives error
D
None of the above
11
Condition in loops is checked based on the value of a variable called the ___
A
loop’s special variable
B
loop’s control variable
C
loop’s execution variable
D
None of the above
12
When the condition in loops becomes false, the loop _________
A
terminates
B
begin
C
restart
D
None of the above
13
If the condition given in the loop never return False then the loop ______
A
never ends
B
ends after 50 times execution
C
ends after 150 times execution
D
give error
14
Write the output of the following code : for i in range(5): print(i)
A
0 1 2 3 4
B
1 2 3 4 5
C
1 2 3 4
D
Error
15
Write the output of the following code : for i in (1,2,3): print(i)
A
1 2 3
B
1 2
C
0 1 2
D
Error
16
Write the output of the following code : for i in (2,3,4): print("i")
A
2 3 4
B
2 3
C
i i i
D
Error
17
Write the output of the following code : for i in range(10,2,-2): print(i, "Hello")
A
10 Hello 8 Hello 6 Hello 4 Hello
B
10 8 6 4 Hello Hello Hello Hello
C
10 Hello 8 Hello 6 Hello 4 Hello 2 Hello d.
D
Error
18
Write the output of the following code : str = "Python Output based Questions" word=str.split() for i in word: print(i)
A
Python Output based Questions
B
Python Output based Questions
C
PythonOutputbasedQuestions
D
Error
19
Write the output of the following code : for i in range(7,10): print("Flow of control in Python") print("Flow of control in Python")
A
Flow of control in Python Flow of control in Python Flow of control in Python Flow of control in Python
B
Flow of control in Python Flow of control in Python
C
Flow of control in Python
D
Error
20
Write the output of the following code : for i in range(7,-2,-9): for j in range(i): print(j)
A
0 1 2 3 4 5 6
B
1 2 3 4 5 6
C
0 1 2 3 4 5
D
0 1 2 3
21
Write the output of the following code : i="9" for k in i: print(k)
A
4
B
9
C
8
D
5
22
Write the output of the following code : for i in range(1, 8): print(i) i+=2
A
1 2 3 4 5 6 7
B
0 1 2 3 4 5 6
C
1 2 3 4 5 6
D
Error
23
Write the output of the following code : for i in range(4, 7): i=i+3 print("Hello")
A
Hello Hello Hello
B
Hello Hello
C
Hello world H
D
Error
24
Write the output of the following code : for i in range(4,7): i=i+3 print("Hello", i)
A
Hello 7 Hello 8 Hello 9
B
Hello 4 Hello 5 Hello 6
C
Hello 4
D
Error
25
Write the output of the following code : i=4 while(i<10): i=i+3 print(i)
A
7 10
B
4 5 6 7 8 9
C
7
D
Error
26
Write the output of the following code : for i in range(20): if i//4==0: print(i)
A
0 1 2 3
B
0 5 10 15
C
5 10 15
D
Error
27
Write the output of the following code : x=1234 while x%10: x=x//10 print(x)
A
123 12 1
B
123 12 1 0
C
123 12
D
Error
28
Write the output of the following code : for i in 1,2,3: print(i*i)
A
1 4 9
B
1 2 3
C
1 2 3 4
D
Error
29
Write the output of the following code : for i in 2,4,6: print("H"*i)
A
HH HHH HHHHH
B
HH HHHH HHHHHH
C
H HH HHHH HHHHHH
D
Error
30
Write the output of the following code : p=10 q=20 p=p*q//4 q=p+q**3 print(p,q)
A
50 8050
B
50 8050
C
50 80 50
D
Error
31
Write the output of the following code : x=2 y=6 x=x+y/2 + y//4 print(x)
A
6
B
6.0
C
5
D
5.0
32
Write the output of the following : a = 7 for i in 7: print(a)
A
Error
B
1 2 3 4 5 6
C
7
D
No output
33
Write the output of the following code : a = "AMIT" for i in range(len(a)): print(a)
A
Error
B
AMIT AMIT AMIT
C
AMIT AMIT AMIT AMIT
D
A M I T
34
A M I T
A
No Output
B
Print “i†infinite times
C
Error
D
print ‘i’ five times
35
Write the output of the following code : print(range (5, 0, -2))
A
range (5, 0, -2)
B
Error
C
No Output
D
5 3 1
36
Write the output of the following code : for i in range(0,2,-1): print("Hello")
A
Hello Hello Hello
B
Hello Hello
C
No Output
D
Error
37
Write the output of the following code : s1="csiplearninghub.com" s2="" s3="" for x in s1: if(x=="s" or x=="n" or x=="p"): s2+=x print(s2,end=" ") print(s3)
A
spnn
B
nspp
C
npss
D
npps
38
Write the output of the following code : s1="csiplearninghub.com" c=0 for x in s1: if(x!="l"): c=c+1 print(c)
A
16
B
19
C
17
D
18
39
Write the output of the following code : j=12 c=9 while(j): if(j>5): c=c+j-2 j=j-1 else: break print(j, c)
A
6 58
B
5 58
C
Error
D
5 60
40
Write the output of the following code : L = [13 , 12 , 21 , 16 , 35 , 7, 4] sum = 5 sum1 = 3 for i in L: if (i % 4 == 0): sum = sum + i continue if (i % 7 == 0): sum1 = sum1 + i print(sum , end=" ") print(sum1)
A
37 66
B
32 66
C
35 66
D
38 66
41
Write the output of the following code : print('cs' + 'ip' if '234'.isdigit( ) else 'IT' + '-402')
A
IT-402
B
cs
C
csip
D
Error
42
Write the output of the following: a=10 while a>5: if a%7==0: print(a**2,end='@') else: print(a-1,end='@') a=a-3
A
9@7@49@
B
9@49@
C
9@49
D
9@7@5@
43
How many times the following loop will execute? s1="flow of control in python" for i in s1[1:5]: print()
A
5
B
4
C
3
D
2
44
Write the output of the following: s=0 L = [2, 4, 6, 8, 10] for i in range(1,len(L),1): s = s + L[i] print(s)
A
28
B
30
C
24
D
26
45
How many times “Bye†will print: s=0 L = [2, 4, 6, 8, 10] for i in range(len(L)): if L[i]//2==1: print("Bye")
A
4
B
3
C
2
D
1
46
How many times “Bye†will print: s=0 L = [2, 4, 6, 8, 10] for i in range(len(L)): if L[i]//2==1: print("Bye")
A
[‘A’, ‘B’, ‘C’]
B
[ ]
C
[‘A’, ‘B’]
D
[‘A’, ‘C’, ‘E’]
47
Write the output of the following: def ch(st): str ="" for i in range(1,4): if i%2==0: str=str+st[i] elif st[i].lower(): str = str + st[i-1] else: str=str+st[i] print('-'. join (str)) ch('flow')
A
f-o-o
B
-f-o-o-
C
f-o-o-
D
f-o-
48
Write the output of the following: st1="Flow91" st2="gun" I=0 while I<len(st1): if st1[I]>="a" and st1[I]<="z": st2=st2+st1[I+1] elif st1[I]>="0" and st1[I]<="9": st2=st2+st1[I-1] else: st2=st2+"?" I=I+1 print(st2)
A
gun?ow9w
B
gun?ow9w9
C
gun??w9w9
D
gun?ow9w?
49
Write the output of the following: T=["flow","of","Control"] T1=range(len(T)) for i in T1: print(T[i].upper(), end="-")
A
FLOW-OF-CONTROL-
B
FLOW-OF-CONTROL
C
FLOW-OF-CONTROL
D
FLOWOFCONTROL
50
FLOWOFCONTROL
A
1+2+3+
B
1+2+3+final+
C
1+2+3+final
D
6+final
51
Syntax of ‘for’ loop is given below: for < _________ > in <sequence/ items in range>:
A
control-variable
B
central-variable
C
center-variable
D
repeater-variable
52
Which of the following statement is not correct about ‘for’ loop?
A
The ‘for’ loop is used to iterate over a range of values or a sequence.
B
The ‘for’ loop is executed for each of the items in the range.
C
While using ‘for’ loop, it is known in advance the number of times the loop will execute
D
None of the above
53
________ function is used in for loops for generating a sequence of numbers.
A
update( )
B
len( )
C
range( )
D
pop( )
54
Which of the following parameter of range( ) function is optional?
A
Start
B
Step
C
Both of the above
D
Stop
55
______ statement terminates the current loop and resumes execution of the statement following that loop.
A
Continue
B
Break
C
Exit
D
Quit
56
____________ statement skips the execution of remaining statements inside the body of the loop for the current iteration and jumps to the beginning of the loop for the next iteration
A
Continue
B
Break
C
Pass
D
Quit
57
A loop inside another loop is called ______
A
inner loop
B
nested loop
C
rest loop
D
None of the above
58
If the condition of the while loop is initially false, then the loop will execute ___
A
One time only
B
Three times only
C
Two times only
D
Zero time
59
Write the output of the following : for x in range(1,4): for y in range(2,5): if x * y > 10: break print (x * y, end=" ")
A
2 3 4 4 6 8 6
B
2 3 4 4 6 8 6 9
C
3 4 4 6 8 6 9
D
2 3 4 4 6 8 6 9 9
60
Write the output of the following: var = 7 while var > 0: print ('Current variable value: ', var) var = var -1 if var == 3: break else: if var == 6: var = var -1 continue print ("Good bye!")
A
Current variable value: 7 Current variable value: 5 Good bye! Current variable value: 4
B
Current variable value: 7 Current variable value: 5 Current variable value: 4
C
Current variable value: 7 Current variable value: 6 Current variable value: 5 Current variable value: 4
D
Current variable value: 7 Good bye! Current variable value: 5 Current variable value: 4
61
Execution of which statement is not dependent on the condition? if i <=4 : print("Hello") #Statement 1 print("How") #Statement 2 else: print("are") #Statement 3 print("You") #Statement 4
A
Statement 1
B
Statement 2
C
Statement 3
D
Statement 4
62
Which of the following statement will return error?
A
for i in a : #a is a list
B
for i in range(5) :
C
for i not in a : # a is a list
D
for i in (1, 2, 3) :
63
How many times the following loop will execute? a = [10, 11, 12, 13, 45] for a[3] in a: print("Flow")
A
5
B
12
C
13
D
6
64
Write the output of the following: for l in range(3): if l == 2: continue else: print("i",end = " ") else: print("Here")
A
i i i Here
B
i i iHere
C
i i i
D
i i Here i
65
Which of the following is an empty statement in python?
A
Pass
B
Continue
C
Break
D
Exit
66
Which of the following is jump statement in python?
A
Pass
B
Continue
C
Break
D
Break and Continue
67
Which symbol is used to end loop and conditional statements?
A
Semicolon(;)
B
Comma(,)
C
Colon(:)
D
Exclamation(!)
68
Write the output of the following: St="Amit" for i in St: St.swapcase() print(St)
A
Amit
B
aMIT
C
aMiT
D
AMit
69
What will be the value of ‘m’ and ‘n’ after execution of following code: m = 3; for n in range(2, 7, 2): n *= m n = n-1
A
3 and 15
B
3 and 17
C
5 and 17
D
5 and 15
70
What will be the value of ‘n’ and ‘n1’ after execution of following code: n1=10 for n in range(10, 12): n1=n ** 2 n1=n1-10
A
111 and 11
B
11 and 12
C
11 and 111
D
12 and 11
71
What will be the value of ‘n’ and ‘n1’ after execution of following code: n1=10 for n in range(10, 12): n1=n ** 2 n1=n1-10
A
111 and 11
B
11 and 12
C
11 and 111
D
12 and 11
72
Write the output of the following: k = 5 sk = 0; while k <= 12: sk = sk + k k = k + 4 print(sk, k)
A
14 14
B
13 14
C
14 13
D
13 13
Submit Quiz
Back to All Quizzes