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?




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




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




4. Which of the following value of ‘x’ makes the condition False in the given code?




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




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




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




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




9. Repetition of a set of statements in a program is made possible using _____




10. The statements in a loop are executed repeatedly as long as particular condition ___




11. Condition in loops is checked based on the value of a variable called the ___




12. When the condition in loops becomes false, the loop _________




13. If the condition given in the loop never return False then the loop ______




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




32. Write the output of the following : a = 7 for i in 7: print(a)




33. Write the output of the following code : a = "AMIT" for i in range(len(a)): print(a)




34. A M I T




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




36. Write the output of the following code : for i in range(0,2,-1): print("Hello")




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)




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)




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)




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)




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




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




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




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)




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




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




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




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)




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




50. FLOWOFCONTROL




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




52. Which of the following statement is not correct about ‘for’ loop?




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




54. Which of the following parameter of range( ) function is optional?




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




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




57. A loop inside another loop is called ______




58. If the condition of the while loop is initially false, then the loop will execute ___




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




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




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




62. Which of the following statement will return error?




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




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




65. Which of the following is an empty statement in python?




66. Which of the following is jump statement in python?




67. Which symbol is used to end loop and conditional statements?




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




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




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




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




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