Python/MCQ on Flow of Control in Python Set 2 Sample Test,Sample questions

Question:
 FLOWOFCONTROL

1. 1+2+3+

2.1+2+3+final+

3.1+2+3+final

4.6+final


Question:
 Syntax of ‘for’ loop is given below:
for < _________ > in <sequence/ items in range>:

1.control-variable

2.central-variable

3.center-variable

4.repeater-variable


Question:
 Which of the following is jump statement in python?

1.Pass

2.Continue

3.Break

4.Break and Continue


Question:
 Which of the following parameter of range( ) function is optional?

1.Start

2.Step

3.Both of the above

4.Stop


Question:
 Which of the following statement is not correct about ‘for’ loop?

1.The ‘for’ loop is used to iterate over a range of values or a sequence.

2.The ‘for’ loop is executed for each of the items in the range.

3. While using ‘for’ loop, it is known in advance the number of times the loop will execute

4.None of the above


Question:
 Write the output of the following code :
for i in range(4, 7):
      i=i+3
     print("Hello")

1.Hello Hello Hello

2. Hello Hello

3.Hello world H

4.Error


Question:
 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")

1.Flow of control in Python Flow of control in Python Flow of control in Python Flow of control in Python

2.Flow of control in Python Flow of control in Python

3.Flow of control in Python

4.Error


Question:
 Write the output of the following code :
print(range (5, 0, -2))

1.range (5, 0, -2)

2.Error

3.No Output

4.5 3 1


Question:
 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)

1.gun?ow9w

2.gun?ow9w9

3.gun??w9w9

4.gun?ow9w?


Question:
A
M
I
T

1.No Output

2.Print “i” infinite times

3.Error

4. print ‘i’ five times


Question:
A loop inside another loop is called ______

1. inner loop

2.nested loop

3.rest loop

4.None of the above


Question:
Condition in loops is checked based on the value of a variable called the ___

1.loop’s special variable

2. loop’s control variable

3.loop’s execution variable

4.None of the above


Question:
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

1.Statement 1

2.Statement 2

3.Statement 3

4.Statement 4


Question:
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")

1.4

2.3

3.2

4.1


Question:
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")

1.[‘A’, ‘B’, ‘C’]

2. [ ]

3. [‘A’, ‘B’]

4. [‘A’, ‘C’, ‘E’]


Question:
How many times the following loop will execute?
a = [10, 11, 12, 13, 45]
for a[3] in a:
     print("Flow")

1.5

2.12

3.13

4.6


Question:
How many times the following loop will execute?
s1="flow of control in python"
for i in s1[1:5]:
   print()

1.5

2.4

3.3

4.2


Question:
If the condition given in the loop never return False then the loop ______

1.never ends

2.ends after 50 times execution

3.ends after 150 times execution

4.give error


Question:
If the condition of the while loop is initially false, then the loop will execute ___

1. One time only

2. Three times only

3.Two times only

4.Zero time


Question:
Repetition of a set of statements in a program is made possible using _____

1.Selection Constructs

2.Sequential Constructs

3.Looping Constructs

4.None of the above


Question:
The statements in a loop are executed repeatedly as long as particular condition ___

1.remains False

2.remains True

3.gives error

4.None of the above


Question:
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

1.3 and 15

2. 3 and 17

3. 5 and 17

4.5 and 15


Question:
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

1.111 and 11

2.11 and 12

3.11 and 111

4.12 and 11


Question:
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

1.111 and 11

2.11 and 12

3.11 and 111

4.12 and 11


Question:
When the condition in loops becomes false, the loop _________

1.terminates

2.begin

3.restart

4.None of the above


Question:
Which of the following is an empty statement in python?

1.Pass

2.Continue

3.Break

4.Exit


Question:
Which of the following is not a conditional statement in Python?

1.if statement

2.if – else statement

3.if – elif statement

4.None of the above


Question:
Which of the following statement will return error?

1.for i in a : #a is a list

2.for i in range(5) :

3.for i not in a : # a is a list

4.for i in (1, 2, 3) :


Question:
Which of the following symbol is used to end an ‘if’ statement in Python?

1.Comma( , )

2.Colon( : )

3.Semi Colon( ; )

4.None of the above


Question:
Which of the following value of ‘x’ makes the condition False in the given code?

1.8

2.9

3.5

4.33


Question:
Which symbol is used to end loop and conditional statements?

1.Semicolon(;)

2.Comma(,)

3.Colon(:)

4.Exclamation(!)


Question:
Write the output of the following :

a = 7
for i in 7:
    print(a)

1.Error

2.1 2 3 4 5 6

3.7

4.No output


Question:
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=" ")

1.2 3 4 4 6 8 6

2.2 3 4 4 6 8 6 9

3.3 4 4 6 8 6 9

4.2 3 4 4 6 8 6 9 9


Question:
Write the output of the following :
if 'i' == "i" :
 print(True)
else:
 print("False")

1.True

2.False

3.Error

4.None of the above


Question:
Write the output of the following :
x = 10
if x > 7 and x <= 10:
 print("Pass", end="")
 print("Fail")

1.Pass

2.Fail

3.Pass Fail

4.PassFail


Question:
Write the output of the following code :

a = "AMIT"
for i in range(len(a)):
      print(a)

1.Error

2. AMIT AMIT AMIT

3.AMIT AMIT AMIT AMIT

4.A M I T


Question:
Write the output of the following code :

for i in range(0,2,-1):
     print("Hello")

1.Hello Hello Hello

2.Hello Hello

3.No Output

4.Error


Question:
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)

1.6 58

2.5 58

3.Error

4.5 60


Question:
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)

1. 37 66

2.32 66

3. 35 66

4.38 66


Question:
Write the output of the following code :

s1="csiplearninghub.com"
c=0
for x in s1:
     if(x!="l"):
          c=c+1
print(c)

1.16

2.19

3.17

4.18


Question:
Write the output of the following code :
for i in (1,2,3):
   print(i)

1.1 2 3

2.1 2

3.0 1 2

4.Error


Question:
Write the output of the following code :
for i in (2,3,4):
   print("i")

1.2 3 4

2.2 3

3.i i i

4.Error


Question:
Write the output of the following code :
for i in 1,2,3:
    print(i*i)

1. 1 4 9

2.1 2 3

3.1 2 3 4

4.Error


Question:
Write the output of the following code :
for i in 2,4,6:
    print("H"*i)

1.HH HHH HHHHH

2.HH HHHH HHHHHH

3.H HH HHHH HHHHHH

4.Error


Question:
Write the output of the following code :
for i in range(1, 8):
      print(i)
      i+=2

1. 1 2 3 4 5 6 7

2.0 1 2 3 4 5 6

3.1 2 3 4 5 6

4.Error


Question:
Write the output of the following code :
for i in range(10,2,-2):
      print(i, "Hello")

1.10 Hello 8 Hello 6 Hello 4 Hello

2.10 8 6 4 Hello Hello Hello Hello

3.10 Hello 8 Hello 6 Hello 4 Hello 2 Hello d.

4.Error


Question:
Write the output of the following code :
for i in range(20):
    if i//4==0:
        print(i)

1. 0 1 2 3

2.0 5 10 15

3.5 10 15

4.Error


Question:
Write the output of the following code :
for i in range(4,7):
      i=i+3
      print("Hello", i)

1.Hello 7 Hello 8 Hello 9

2.Hello 4 Hello 5 Hello 6

3.Hello 4

4.Error


Question:
Write the output of the following code :
for i in range(5):
 print(i)

1.0 1 2 3 4

2.1 2 3 4 5

3.1 2 3 4

4.Error


Question:
Write the output of the following code :
for i in range(7,-2,-9):
      for j in range(i):
            print(j)

1.0 1 2 3 4 5 6

2.1 2 3 4 5 6

3.0 1 2 3 4 5

4.0 1 2 3


Question:
Write the output of the following code :
i="9"
for k in i:
      print(k)

1.4

2.9

3.8

4.5


Question:
Write the output of the following code :
i=4
while(i<10):
    i=i+3
    print(i)

1.7 10

2.4 5 6 7 8 9

3.7

4.Error


Question:
Write the output of the following code :
p=10
q=20
p=p*q//4
q=p+q**3
print(p,q)

1.50 8050

2.50 8050

3.50 80 50

4.Error


Question:
Write the output of the following code :
print('cs' + 'ip' if '234'.isdigit( ) else 'IT' + '-402')

1.IT-402

2.cs

3.csip

4.Error


Question:
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)

1. spnn

2.nspp

3.npss

4.npps


Question:
Write the output of the following code :
str = "Python Output based Questions"
word=str.split()
for i in word:
     print(i)

1.Python Output based Questions

2.Python Output based Questions

3.PythonOutputbasedQuestions

4.Error


Question:
Write the output of the following code :
x=1234
while x%10:
    x=x//10
    print(x)

1.123 12 1

2.123 12 1 0

3.123 12

4.Error


Question:
Write the output of the following code :
x=2
y=6
x=x+y/2 + y//4
print(x)

1. 6

2. 6.0

3.5

4.5.0


Question:
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')

1.f-o-o

2.-f-o-o-

3. f-o-o-

4.f-o-


Question:
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

1.9@7@49@

2. 9@49@

3.9@49

4.9@7@5@


Question:
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")

1.Error

2.Hello

3.B

4.A


Question:
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")

1. What

2.Hello

3.B

4.A


Question:
Write the output of the following:
for l in range(3):
   if l == 2:
      continue
   else:
      print("i",end = " ")
else:
   print("Here")

1.i i i Here

2.i i iHere

3. i i i

4.i i Here i


Question:
Write the output of the following:
if (3+8//2 != 7):
 print("H")
else:
 print("B")

1.H

2.B

3.Error

4.None of the above


Question:
Write the output of the following:
k = 5
sk = 0;
while k <= 12:
    sk = sk + k
    k = k + 4
print(sk, k)

1.14 14

2.13 14

3.14 13

4.13 13


Question:
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)

1.28

2.30

3.24

4.26


Question:
Write the output of the following:
St="Amit"
for i in St:
   St.swapcase()
print(St)

1.Amit

2.aMIT

3.aMiT

4.AMit


Question:
Write the output of the following:
T=["flow","of","Control"]
T1=range(len(T))
for i in T1:
    print(T[i].upper(), end="-")

1.FLOW-OF-CONTROL-

2.FLOW-OF-CONTROL

3.FLOW-OF-CONTROL

4. FLOWOFCONTROL


Question:
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!")

1.Current variable value: 7 Current variable value: 5 Good bye! Current variable value: 4

2.Current variable value: 7 Current variable value: 5 Current variable value: 4

3.Current variable value: 7 Current variable value: 6 Current variable value: 5 Current variable value: 4

4.Current variable value: 7 Good bye! Current variable value: 5 Current variable value: 4


Question:
______ statement terminates the current loop and resumes execution of the statement following that loop.

1.Continue

2.Break

3.Exit

4.Quit


Question:
________ function is used in for loops for generating a sequence of numbers.

1.update( )

2.len( )

3.range( )

4.pop( )


Question:
____________ 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

1.Continue

2.Break

3.Pass

4.Quit


More MCQS

  1. Python MCQS - Function
  2. Python MCQS - GUI in python
  3. Python MCQS - Operators
  4. Python MCQS - Data type in python
  5. Python MCQS - loops in python
  6. Python MCQS - Numpy
  7. Python MCQS - sqlite3
  8. Python MCQS - Library
  9. Python MCQS - Pandas
  10. Python MCQs
  11. Dictionary Python MCQ set 1
  12. Dictionary Python MCQ set 2
  13. MCQ For Python Fundamentals
  14. MCQ Introduction to Python Section 1
  15. MCQ Introduction to Python Section 2
  16. MCQ Introduction to Python Section 3
  17. MCQ on Flow of Control in Python Set 1
  18. MCQ on Flow of Control in Python Set 2
  19. MCQ on Python String Set 1
  20. File Handling in Python section 1
  21. File Handling in Python section 2
  22. Python Functions MCQS Set 1
  23. Python Functions MCQS Set 2
  24. MCQ on List in Python
  25. Pandas MCQ Questions Set 1
  26. Pandas MCQ Questions Set 2
  27. Tuple MCQ in Python
  28. Python dataframe MCQ
  29. Python Mcq Set 1
  30. Python Mcq Set 2
  31. Python Mcq Set 3
  32. Python Mcq Set 4
  33. Python Mcq Set 5
  34. Python Mcq Set 6
  35. Python Mcq Set 7
  36. Python Mcq Set 8
  37. Python Mcq Set 9
  38. Python Mcq Set 10
  39. Python Mcq Set 11
  40. Python Mcq Set 12
  41. Python Mcq Set 13
  42. Python Mcq Set 14
  43. Python Mcq Set 15
  44. Python Mcq Set 16
  45. Python Mcq Set 17
  46. Python Mcq Set 18
  47. Python Mcq Set 19
  48. Python Mcq Set 20
  49. Python Mcq Set 21
  50. Python MCQ
  51. Python MCQ Questions with Answer
  52. Test
  53. python mcq question and answer
Search
Olete Team
Online Exam TestTop Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on Online Exam Testwebsite is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!