50+ MCQ on Working with functions in python Class 12

Revision Tour of Topics covered in Class 11

1. A function in python begins with which keyword?

a) void

b) return

c) int

d) Def

d) Def

 

2. Which of the following items are present in the function header?

a) function name

b) parameter list

c) return value

d) Both a and b 

d) Both a and b 

 

3. What is called when a function is defined inside a class?

a) class

b) function

c) method

d) module

c) method

 

4. If return statement is not used inside the function, the function will return:

a) None 

b) 0

c) Null

d) Arbitary value

a) None 

 

5. What is a recursive function?

a) A function that calls other function.

b) A function which calls itself. 

c) Both a and b

d) None of the above

b) A function which calls itself. 

 

6. Which of the following is the use of id() function in python?

a) Id() returns the size of object.

b) Id() returns the identity of the object. 

c) Both A and B

d) None of the above

b) Id() returns the identity of the object. 

 

7. Which of the following function headers is correct?

a) def fun(a = 2, b = 3, c)

b) def fun(a = 2, b, c = 3)

c) def fun(a, b = 2, c = 3) 

d) def fun(a, b, c = 3, d)

c) def fun(a, b = 2, c = 3) 

Explanation: All required parameters must be placed before any default arguments. Simply because they are mandatory, whereas default arguments are not. Syntactically, it would be impossible for the interpreter to decide which values match which arguments if mixed modes were allowed. A SyntaxError is raised if the arguments are not given in the correct order. So, option C is correct.

 

8. In which part of memory does the system stores the parameter and local variables of function call?

a) heap

b) stack

c) Uninitialized data segment

d) None of the above

b) stack

 

9. How is a function declared in Python?

a) def function function_name():

b) declare function function_name():

c) def function_name():

d) declare function_name():

c) def function_name():

 

10. Which one of the following is the correct way of calling a function?

a) function_name()

b) call function_name()

c) ret function_name()

d) function function_name()

a) function_name()

 

11. You can also create your own functions, these functions are called?

a) built-in functions

b) user-defined functions

c) py function

d) None of the above

b) user-defined functions

 

12. ___________ are the arguments passed to a function in correct positional order.

a) Required arguments

b) Keyword arguments

c) Default arguments

d) Variable-length arguments

a) Required arguments

 

13. Which of the following will print the pi value defined in math module?

a) print(pi)

b) print(math.pi)

c) from math import pi
print(pi) 

d) from math import pi
print(math.pi)

c) from math import pi
print(pi) 

 

14. What is a variable defined outside a function referred to as?

a) local variable

b) global variable

c) static Variable

d) automatic variable

b) global variable

 

15. Which one of the following is incorrect?

a) The variables used inside function are called local variables.

b) The local variables of a particular function can be used inside other functions, but these cannot be used in global space

c) The variables used outside function are called global variables

d) In order to change the value of global variable inside function, keyword global is used.

b) The local variables of a particular function can be used inside other functions, but these cannot be used in global space

 

16. Name the statement that sends back a value from a function

a) print

b) input

c) return 

d) None

c) return 

 

17.What is the output of the program given below:

x=50

def func(x):

x=2

func(x)

print(‘x is now’,x)

 

a) x is now 50

b) x is now 2

c) x is now 100

d) Error

a) x is now 50

 

18. What is the output of the program given below:

import random

x = random.random()

y= random.randint(0,4)

print(int(x),”:”, y+int(x))

 

a) 0: 0

b) 2 : 4

c) 1: 6

d) 0 : 5

a) 0: 0

 

19. What is the output of the program given below:

def cal(a,b,c):

return a*3,b*3,c*3

val=cal(10,12,14)

print(type(val))

print(val)

 

a) [30, 24, 28]

b) [30,36,42] 

c) [10, 20, 30]

d) [10,12,14]

b) [30,36,42] 

 

20.What is the output of the expression: round(4.576)

a) 4.5

b) 5

c) 4

d) 4.6

b) 5

 

21.What is the output of the function shown below?

import math

abs(math.sqrt(25))

a) Error

b) -5

c) 5

d) 5.0

d) 5.0

 

22.What is the output of the functions shown below? >>>min(max(False,-3,-4), 2,7)

a) 2

b) False 

c) -3

d) -4

b) False 

 

23.What are the outcomes of the function shown below?

>>> x=3

>>>eval(‘x**2’)

a) Error

b) 1

c) 9 

d) 6

c) 9 

 

24.Which of the following functions does not throw an error?

a) ord()

b) ord(‘ ‘)

c) ord(”) 

d) ord(“”)

b) ord(‘ ‘)

 

25.What is the output of below program?

def say(message, times = 1):

print(message * times , end =’ ‘)

say(‘Hello and’)

say(‘World’, 5)

a) Hello and WorldWorldWorldWorldWorld

b) Hello and World 5

c) Hello and World,World,World,World,World

d) Hello and HelloHelloHelloHelloHello

a) Hello and WorldWorldWorldWorldWorld

 

26.What is a variable defined inside a function referred to as?

a) A global variable

b) A volatile variable

c) A local variable 

d) An automatic variable

c) A local variable 

 

27.How many keyword arguments can be passed to a function in a single function call?

a) zero

b) one

c) zero or more 

d) one or more

c) zero or more 

 

28. How are required arguments specified in the function heading?

a) identifier followed by an equal to sign and the default value

b) identifier followed by the default value within backticks (“)

c) identifier followed by the default value within square brackets ([ ])

d) identifier

a) identifier followed by an equal to sign and the default value

 

29. What is returned by

>>> math.ceil(3.4)?

a) 3

b) 4 

c) 4.0

d) 3.0

b) 4 

 

30. What is the value returned by

>>> math.floor(3.4)

a) 3

b) 4

c) 4.0 

d) 3.0

a) 3

 

31.What is returned by

>>> math.ceil(-3.4)?

a) 3

b) 4

c) 4.0 

d) -3

d) -3

 

32.What is the value returned by

>>> math.floor(-3.4)

a) 3

b) -4 

c) 4.0

d) 3.0

b) -4 

 

33.What is displayed on executing print(math.fabs(-3.4))?

a) -3.4

b) 3.4

c) 3 

d) -3

b) 3.4

 

34.What is output of print(math.pow(3, 2))?

a) 9

b) 9.0 

c) None

d) None of these

b) 9.0 

 

35.What is the value of x if x = math.sqrt(4)?

a) 2

b) 2.0 

c) (2, -2)

d) (2.0, -2.0)

b) 2.0 

 

36.To include the use of functions which are present in the random library, we must use the option:

a) import random

b) random.h

c) import.random

d) random.random

a) import random

 

37.What is the output of the code shown below?

import random

random.choice(2,3,4)

 

a) An integer other than 2, 3 and 4

b) Either 2, 3 or 4

c) Error

d) 3 only

b) Either 2, 3 or 4

 

38. What is the output of the function shown below (random module has already been imported)?

>>>random.choice(‘sun’)

a) sun

b) u

c) either s, u or n 

d) Error

c) either s, u or n 

 

39.What is the output of the function shown below if the random module has already been imported?

>>>import random

>>>random.randint(3.5,7)

a) Error

b) Any integer between 3.5 and 7, including 7

c) Any integer between 3.5 and 7, excluding 7

d) The integer closest to the mean of 3.5 and 7

b) Any integer between 3.5 and 7, including 7

 

40.Which type of elements are accepted by random.shuffle()?

a) strings

b) lists 

c) tuples

d) integers

b) lists 

 

 

41.Which of the following statements are True out of the given below:

1) More than one value(s) can be returned by a function

2) The variable declared inside a function is a Global variable.

3) Once the function is defined , it may be called only once

4) A function is used by invoking it

 

a) 1 & 2

b) 1 & 4 

c) 2 & 3

d) 2 & 4

b) 1 & 4 

 

42.What will be the output of the following code:

A=1

def f ():

A=10

print(A)

 

a) 1

b) 10

c) Error

d) None

a) 1

 

43.>>>def Interest(p,c,t=2,r=0.09):

return p*t*r

Considering the above defined function which of following function call are legal.

1) Interest(p=1000,c=5)

2) Interest(r=0.05,5000,3)

3) Interest(500,t=2,r=0.05)

4) Interest(c=4,r=0.12,p=5000)

 

a) 1 , 2 and 4

b) 2 & 3

c) 1 &4 

d) 3 & 4

c) 1 &4 

 

44. The function can be called in the program by writing function name followed by ____

a) [ ]

b) { }

c) ( )

d) None of the above

c) ( )

 

45. The built-in function sin() belongs to which module:

a) random

b) pandas

c) math 

d) numpy

c) math 

 

46. …………..function returns the smallest integer greater than the given floating point number.

a) floor()

b) ceil()

c) sqrt()

d) CEIL()

b) ceil()

 

47. .…………function will return the largest integer less than the given floating point number.

a) floor()

b) ceil()

c) sqrt()

d) CEIL()

a) floor()

 

48. .………..function returns the length of the object being passed.

a) Length()

b) Len()

c) len()

d) count()

c) len()

 

49. .………..function returns the absolute value.

a) Abs( )

b) abs( ) 

c) absolute( )

d) None of these

b) abs( ) 

 

50. The range(x) function will generate the series of numbers from :

a) Min to max

b) o to x-1

c) o to x

d) x

b) o to x-1

 

51. .……….. function can identify the whitespace in a given string.

a) Space( )

b) isspace( ) 

c) Isspace( )

d) is_space( )

b) isspace( ) 

 

52. Consider the statement given below and answer the question:

>>>S=’My name is Ravindra’

Which statement will print “True” out of the given :

a) print(S.isspace( ))

b) print (s.isspace( ))

c) print(S[2].isspace)

d) print(S[2].isspace( )) 

d) print(S[2].isspace( )) 

 

53. A variable declared outside all the functions in a python program, then mention the statements which are True in the context of the variable.

1) This variable will have global scope.

2) This variable will not be accessible from anywhere in the prog.

3) This variable will have a large lifetime than local variable.

4) This variable will be referred as Local variable.

 

a) Only 1&2

b) Only 1

c) Only 1&3

d) Only 3

c) Only 1&3

 

Comments are closed.

Copywrite © 2020-2024, CBSE Python,
All Rights Reserved
error: Content is protected !!