Python MCQ Quiz Hub

Python Functions MCQS Set 1

Choose a topic to test your knowledge and improve your Python skills

1. The process of dividing a computer program into separate independent blocks of code with specific functionalities is known as _________.




2. _____________ can be defined as a named group of instructions that accomplish a specific task when it is invoked/called.




3. In a program, a function can be called ____________ times.




4. Which keyword is used to begin the definition of a function?




5. Which of the following statement is a function call?




6. Which of the following are advantages of using function in program?




7. Function defined to achieve some task as per the programmer’s requirement is called a __




8. Functions which are already defined in python is called a ________




9. Which of the following statement is not true regarding functions?




10. Which of the following statement is outside the function “sum”? def sum(): a = int(input(“Enter number”))#Statement 1 b = int(input(“Enter number”)) #Statement 2 s = a + b #Statement 3 print(s) #Statement 4




11. The function can be called in the program by writing function name followed by ___




12. def cal(n1) : What is n1?




13. Write the output of the following: def s(n1): print(n1) n2=4 s(n2)




14. Which of the following statement will execute in last? def s(n1): #Statement 1 print(n1) #Statement 2 n2=4 #Statement 3 s(n2) #Statement 4




15. Choose the correct answer: def s(n1): print(n1) n2=4 s(n2) Statement A : n1 and n2 have same memory Address Statement B : both n1 and n2 are referring to the same value, so they have same identity




16. Consider the following code and choose the incorrect statement.: def s(n1): print(id(n1)) n2=4 s(n2) print(id(n2))




17. Write the output of the following: def cal(m,n): if m==n: return m*3 else: return m*2 s = cal(9, 8) print(s)




18. Write the output of the following: def cal(m,n): if m==n: return m*3 else: return n*2 s = cal("Amit", "Anuj") print(s)




19. Write the output of the following: def fn(n1, n2=7): n1=n1+n2 print(n1) fn(3, 9)




20. Write the output of the following: def fn(n1, n2=7): n1=n1%n2 print(n1) fn(3%2, 9%2)




21. Which of the following function definition header is wrong?




22. Functions which do not return any value is called ___




23. The ____________ statement returns the values from the function to the calling function.




24. The return statement in function is used to _____




25. Choose the correct statement




26. Write the output of the following: sound() def sound(): print("sound" * 2)




27. A function may return multiple values using _




28. The part of the program where a variable is accessible is known as the __________ of that variable




29. Which of the following is not the scope of variable?




30. A variable that is defined inside any function or a block is known as a ___




31. Fill in the blank so that the output is 9: a = 9 def sound(): ________ a print(a) sound()




32. Write the output of the following: a = 9 def sound(): b = 7 print(a) sound() print(b)




33. How many built-in functions are used in the following code: a = int(input("Enter a number: ") b = a * a print(" The square of ",a ,"is", b)




34. How many built-in functions are used in the following code: a = int(input("Enter a number: ") b = a * a print(" The square of ",a ,"is", b)




35. Which of the following is not the type of function argument?




36. Write the output of the following: print("A") def prnt(): print("B") print("C") prnt()




37. Write the output of the following: def check(): i = 5 while i > 1: if i //2==0: x = i + 2 i = i-1 else: i = i-2 x = i print (x) check()




38. Which module is to be imported for using randint( ) function?




39. Which of the following number can never be generated by the following code: random.randrange(0, 100)




40. Write the output of : print(abs(-45))




41. Write the output of : print(max([1, 2, 3, 4], [4, 5, 6], [7]))




42. Write the output of : print(min(tuple(“computer”)))




43. Choose the incorrect statement.




44. Which of the following return floating point number?




45. A Python standard library consists of a number of modules




46. Arrange the following from Simple(small) to Complex(big). Instructions, Functions, Library, Module




47. A module is save with extension ____________




48. Choose the correct statement to import Math module:




49. Which of the following is not built-in module in python?




50. In math.ceil(x), what is x here?




51. Write the output of the following : print(math.floor(-4.5))




52. Write the output of : print(math.fabs(-6.7))




53. _______ function of math module calculates the factorial.




54. Which of the following function return random real number (float) in the range 0.0 to 1.0?




55. Smallest number return by statement random.randrange(2,7) is _______




56. Which of the following function is not defined in statistics module?




57. In order to get a list of modules available in Python, we can use the __________ statement:




58. Aman wants to import only sqrt( ) function of math module. Help him to write the correct code.




59. Which of the following options can be the output for the following code? import random List=["Delhi","Mumbai","Chennai","Kolkata"] for y in range(4): x = random.randint(1,3) print(List[x],end="#")




60. What will be the output of the following code? x = 3 def myfunc(): global x x+=2 print(x, end=' ') print(x, end=' ') myfunc() print(x, end=' ')




61. Which of the following components are part of a function header in Python? i. function name ii. return statement iii. parameter list iv. def keyword




62. Which of the following function headers is correct?




63. Which of the following is the correct way to call a function?




64. What will be the output of the following Python code? def add (num1, num2): sum = num1 + num2 sum = add(20,30) print(sum)




65. What will be the output of the following code? def my_func(var1=100, var2=200): var1 += 10 var2 = var2 - 10 return var1+var2 print(my_func(50),my_func())




66. What will be the output of the following code? value = 50 def display(N): global value value = 25 if N%7==0: value = value + N else: value = value - N print(value, end="#") display(20) print(value)




67. What is the output of the following code snippet? def ChangeVal(M,N): for i in range(N): if M[i]%5 == 0: M[i]//=5 if M[i]%3 == 0: M[i]//=3 L = [25,8,75,12] ChangeVal(L,4) for i in L: print(i,end="#")




68. What will be the possible outcome of the following code: import random X =[1,2,3,4] m = random.randint(0,3) for i in range(m): print (X[i],"--",end=" ")




69. Write the output of the following code : import random for i in range(random.randint(2, 2)): print(i)




70. Write the output of the following code : import random for i in range(random.randint(2,3)): print("A")




71. What is the minimum and maximum value of ‘A’ in the following statement. import random A=random.randint(2,30) print(A)




72. Write the output of the following code : import random A=random.randrange(20) print(A)




73. Write the output of the following code : import random print(int(random.random( )))




74. Write the output of the following code : import random print(int(random.random()*5))




75. Which of the following subject will never printed in following code? import random L=["English", "Hindi", "Math", "Science", "SST", "CS", "IP"] for i in range(random.randint(1, 6)): print(L[i])




76. What is the minimum and maximum value of ‘v’ in the following statement. import random v=random.randrange(20)-3 print(v)




77. Which of the following method is not included in random module?




78. A = random._______________([1,2,3,4,5]). Fill in the blank so that ‘A’ may have any value from the list.




79. Functions created by user is called _____________ function




80. Division of large programs into smaller programs. These smaller programs are called ____




81. Use of functions _______________ the size of programs.




82. A function can be called __________ times in a program.




83. Which of the following is not a type conversion functions?




84. Write the output of the following. print(int( ))




85. Which of the following statement will return error? print(int("a")) #Statement1 print(str(123)) #Statement2