Python MCQ Quiz Hub

Python Functions MCQS Set 1

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

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





✅ Correct Answer: 2

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





✅ Correct Answer: 1

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





✅ Correct Answer: 4

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





✅ Correct Answer: 3

Which of the following statement is a function call?





✅ Correct Answer: 3

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





✅ Correct Answer: 3

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





✅ Correct Answer: 1

Functions which are already defined in python is called a ________





✅ Correct Answer: 4

Which of the following statement is not true regarding functions?





✅ Correct Answer: 1

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





✅ Correct Answer: 4

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





✅ Correct Answer: 3

def cal(n1) : What is n1?





✅ Correct Answer: 1

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





✅ Correct Answer: 3

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





✅ Correct Answer: 2

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





✅ Correct Answer: 3

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





✅ Correct Answer: 4

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)





✅ Correct Answer: 2

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)





✅ Correct Answer: 4

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





✅ Correct Answer: 2

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





✅ Correct Answer: 1

Which of the following function definition header is wrong?





✅ Correct Answer: 3

Functions which do not return any value is called ___





✅ Correct Answer: 3

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





✅ Correct Answer: 3

The return statement in function is used to _____





✅ Correct Answer: 3

Choose the correct statement





✅ Correct Answer: 3

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





✅ Correct Answer: 3

A function may return multiple values using _





✅ Correct Answer: 2

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





✅ Correct Answer: 1

Which of the following is not the scope of variable?





✅ Correct Answer: 3

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





✅ Correct Answer: 2

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





✅ Correct Answer: 2

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





✅ Correct Answer: 4

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)





✅ Correct Answer: 3

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)





✅ Correct Answer: 4

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





✅ Correct Answer: 3

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





✅ Correct Answer: 4

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





✅ Correct Answer: 3

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





✅ Correct Answer: 2

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





✅ Correct Answer: 2

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





✅ Correct Answer: 3

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





✅ Correct Answer: 3

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





✅ Correct Answer: 1

Choose the incorrect statement.





✅ Correct Answer: 4

Which of the following return floating point number?





✅ Correct Answer: 2

A Python standard library consists of a number of modules





✅ Correct Answer: 1

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





✅ Correct Answer: 4

A module is save with extension ____________





✅ Correct Answer: 1

Choose the correct statement to import Math module:





✅ Correct Answer: 2

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





✅ Correct Answer: 4

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





✅ Correct Answer: 3

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





✅ Correct Answer: 2

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





✅ Correct Answer: 2

_______ function of math module calculates the factorial.





✅ Correct Answer: 3

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





✅ Correct Answer: 1

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





✅ Correct Answer: 1

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





✅ Correct Answer: 4

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





✅ Correct Answer: 1

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





✅ Correct Answer: 2

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





✅ Correct Answer: 4

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





✅ Correct Answer: 1

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





✅ Correct Answer: 4

Which of the following function headers is correct?





✅ Correct Answer: 4

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





✅ Correct Answer: 1

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





✅ Correct Answer: 3

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





✅ Correct Answer: 4

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)





✅ Correct Answer: 2

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





✅ Correct Answer: 2

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





✅ Correct Answer: 4

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





✅ Correct Answer: 1

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





✅ Correct Answer: 3

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





✅ Correct Answer: 2

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





✅ Correct Answer: 1

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





✅ Correct Answer: 2

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





✅ Correct Answer: 2

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





✅ Correct Answer: 3

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





✅ Correct Answer: 3

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





✅ Correct Answer: 3

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





✅ Correct Answer: 2

Functions created by user is called _____________ function





✅ Correct Answer: 3

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





✅ Correct Answer: 1

Use of functions _______________ the size of programs.





✅ Correct Answer: 2

A function can be called __________ times in a program.





✅ Correct Answer: 4

Which of the following is not a type conversion functions?





✅ Correct Answer: 3

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





✅ Correct Answer: 3

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





✅ Correct Answer: 1