R4RIN
MCQS
Python MCQ Quiz Hub
MCQ on Flow of Control in Python
Choose a topic to test your knowledge and improve your Python skills
1. Which of the following is not a conditional statement in Python?
if statement
if – else statement
if – elif statement
None of the above
2. Which of the following symbol is used to end an ‘if’ statement in Python?
Comma( , )
Colon( : )
Semi Colon( ; )
None of the above
3. Write the output of the following : x = 10 if x > 7 and x <= 10: print("Pass", end="") print("Fail")
Pass
Fail
Pass Fail
PassFail
4. Which of the following value of ‘x’ makes the condition False in the given code?
8
9
5
33
5. Write the output of the following : if 'i' == "i" : print(True) else: print("False")
True
False
Error
None of the above
6. Write the output of the following: if (3+8//2 != 7): print("H") else: print("B")
H
B
Error
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")
What
Hello
B
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")
Error
Hello
B
A
9. Repetition of a set of statements in a program is made possible using _____
Selection Constructs
Sequential Constructs
Looping Constructs
None of the above
10. The statements in a loop are executed repeatedly as long as particular condition ___
remains False
remains True
gives error
None of the above
11. Condition in loops is checked based on the value of a variable called the ___
loop’s special variable
loop’s control variable
loop’s execution variable
None of the above
12. When the condition in loops becomes false, the loop _________
terminates
begin
restart
None of the above
13. If the condition given in the loop never return False then the loop ______
never ends
ends after 50 times execution
ends after 150 times execution
give error
14. Write the output of the following code : for i in range(5): print(i)
0 1 2 3 4
1 2 3 4 5
1 2 3 4
Error
15. Write the output of the following code : for i in (1,2,3): print(i)
1 2 3
1 2
0 1 2
Error
16. Write the output of the following code : for i in (2,3,4): print("i")
2 3 4
2 3
i i i
Error
17. Write the output of the following code : for i in range(10,2,-2): print(i, "Hello")
10 Hello 8 Hello 6 Hello 4 Hello
10 8 6 4 Hello Hello Hello Hello
10 Hello 8 Hello 6 Hello 4 Hello 2 Hello d.
Error
18. Write the output of the following code : str = "Python Output based Questions" word=str.split() for i in word: print(i)
Python Output based Questions
Python Output based Questions
PythonOutputbasedQuestions
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")
Flow of control in Python Flow of control in Python Flow of control in Python Flow of control in Python
Flow of control in Python Flow of control in Python
Flow of control in Python
Error
20. Write the output of the following code : for i in range(7,-2,-9): for j in range(i): print(j)
0 1 2 3 4 5 6
1 2 3 4 5 6
0 1 2 3 4 5
0 1 2 3
21. Write the output of the following code : i="9" for k in i: print(k)
4
9
8
5
22. Write the output of the following code : for i in range(1, 8): print(i) i+=2
1 2 3 4 5 6 7
0 1 2 3 4 5 6
1 2 3 4 5 6
Error
23. Write the output of the following code : for i in range(4, 7): i=i+3 print("Hello")
Hello Hello Hello
Hello Hello
Hello world H
Error
24. Write the output of the following code : for i in range(4,7): i=i+3 print("Hello", i)
Hello 7 Hello 8 Hello 9
Hello 4 Hello 5 Hello 6
Hello 4
Error
25. Write the output of the following code : i=4 while(i<10): i=i+3 print(i)
7 10
4 5 6 7 8 9
7
Error
26. Write the output of the following code : for i in range(20): if i//4==0: print(i)
0 1 2 3
0 5 10 15
5 10 15
Error
27. Write the output of the following code : x=1234 while x%10: x=x//10 print(x)
123 12 1
123 12 1 0
123 12
Error
28. Write the output of the following code : for i in 1,2,3: print(i*i)
1 4 9
1 2 3
1 2 3 4
Error
29. Write the output of the following code : for i in 2,4,6: print("H"*i)
HH HHH HHHHH
HH HHHH HHHHHH
H HH HHHH HHHHHH
Error
30. Write the output of the following code : p=10 q=20 p=p*q//4 q=p+q**3 print(p,q)
50 8050
50 8050
50 80 50
Error
31. Write the output of the following code : x=2 y=6 x=x+y/2 + y//4 print(x)
6
6.0
5
5.0
32. Write the output of the following : a = 7 for i in 7: print(a)
Error
1 2 3 4 5 6
7
No output
33. Write the output of the following code : a = "AMIT" for i in range(len(a)): print(a)
Error
AMIT AMIT AMIT
AMIT AMIT AMIT AMIT
A M I T
34. A M I T
No Output
Print “i” infinite times
Error
print ‘i’ five times
35. Write the output of the following code : print(range (5, 0, -2))
range (5, 0, -2)
Error
No Output
5 3 1
36. Write the output of the following code : for i in range(0,2,-1): print("Hello")
Hello Hello Hello
Hello Hello
No Output
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)
spnn
nspp
npss
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)
16
19
17
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)
6 58
5 58
Error
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)
37 66
32 66
35 66
38 66
41. Write the output of the following code : print('cs' + 'ip' if '234'.isdigit( ) else 'IT' + '-402')
IT-402
cs
csip
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
9@7@49@
9@49@
9@49
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()
5
4
3
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)
28
30
24
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")
4
3
2
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’, ‘B’, ‘C’]
[ ]
[‘A’, ‘B’]
[‘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')
f-o-o
-f-o-o-
f-o-o-
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)
gun?ow9w
gun?ow9w9
gun??w9w9
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="-")
FLOW-OF-CONTROL-
FLOW-OF-CONTROL
FLOW-OF-CONTROL
FLOWOFCONTROL
50. FLOWOFCONTROL
1+2+3+
1+2+3+final+
1+2+3+final
6+final
51. Syntax of ‘for’ loop is given below: for < _________ > in <sequence/ items in range>:
control-variable
central-variable
center-variable
repeater-variable
52. Which of the following statement is not correct about ‘for’ loop?
The ‘for’ loop is used to iterate over a range of values or a sequence.
The ‘for’ loop is executed for each of the items in the range.
While using ‘for’ loop, it is known in advance the number of times the loop will execute
None of the above
53. ________ function is used in for loops for generating a sequence of numbers.
update( )
len( )
range( )
pop( )
54. Which of the following parameter of range( ) function is optional?
Start
Step
Both of the above
Stop
55. ______ statement terminates the current loop and resumes execution of the statement following that loop.
Continue
Break
Exit
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
Continue
Break
Pass
Quit
57. A loop inside another loop is called ______
inner loop
nested loop
rest loop
None of the above
58. If the condition of the while loop is initially false, then the loop will execute ___
One time only
Three times only
Two times only
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=" ")
2 3 4 4 6 8 6
2 3 4 4 6 8 6 9
3 4 4 6 8 6 9
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!")
Current variable value: 7 Current variable value: 5 Good bye! Current variable value: 4
Current variable value: 7 Current variable value: 5 Current variable value: 4
Current variable value: 7 Current variable value: 6 Current variable value: 5 Current variable value: 4
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
Statement 1
Statement 2
Statement 3
Statement 4
62. Which of the following statement will return error?
for i in a : #a is a list
for i in range(5) :
for i not in a : # a is a list
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")
5
12
13
6
64. Write the output of the following: for l in range(3): if l == 2: continue else: print("i",end = " ") else: print("Here")
i i i Here
i i iHere
i i i
i i Here i
65. Which of the following is an empty statement in python?
Pass
Continue
Break
Exit
66. Which of the following is jump statement in python?
Pass
Continue
Break
Break and Continue
67. Which symbol is used to end loop and conditional statements?
Semicolon(;)
Comma(,)
Colon(:)
Exclamation(!)
68. Write the output of the following: St="Amit" for i in St: St.swapcase() print(St)
Amit
aMIT
aMiT
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
3 and 15
3 and 17
5 and 17
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
111 and 11
11 and 12
11 and 111
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
111 and 11
11 and 12
11 and 111
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)
14 14
13 14
14 13
13 13
Submit