0% found this document useful (0 votes)
62 views6 pages

Functions Bookback Mcqs

Uploaded by

mathandharsan5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views6 pages

Functions Bookback Mcqs

Uploaded by

mathandharsan5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

1. A function in Python begins with which keyword?

(a) void (b) return (c) int (d) def

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


(a) print (b) input (c) return (d) None

3. Functions that do not return any value are known as:


(a) fruitful functions (b) void functions (c) library functions (d) user-defined
functions

4. A variable created or defined within a function body is classified as:


(a) local (b) global (c) built-in (d) instance

5. Which of the following arguments works with implicit values that are used if
no value is provided?
(a) keyword (b) required (c) variable-length (d) default
6. Which values are used by the functions to communicate information back to
the caller?
(a) local (b) global (c) return (d) random
7. 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

8. Which is the most appropriate definition for recursion?

(a) A function that calls itself


(b) A function execution instance that calls another execution instance of the
same function
(c) A class method that calls another class method
(d) An in-built method that is automatically called

9. Fill in the line of code for calculating the factorial of a number:


def fact (num):
if num == 0 :
________________
return 1
else:
return

(a) num*fact(num-1) (b) (num-1)*(num-2)


(c) num*(num-1) (d) fact(num)*fact(num-1)

10. Which of the following statements is false about recursion?


(a) Every recursive function must have a base case.
(b) Infinite recursion can occur if the base case isn't properly mentioned.
(c) A recursive function makes the code easier to understand.
(d) Every recursive function must have a return value.

11. What is the output of the following snippet?


def fun (n):
if (n > 100):
return n - 5
return fun (fun (n+11))
print (fun (45))

(a) 50 (b) 100 (c) 74 (d) Infinite loop

12. What happens if the base condition isn't defined in recursive programs?
(a) Program gets into an infinite loop
(b) Program runs once
(c) Program runs n number of times, where n is the argument given to the
function
(d) An exception is thrown

13. What is the default return value for a function that does not return any
value explicitly?
(a) None (b) int (c) double (d) null

14. Which of the following items are present in the function header?
(a) function name only (b) both function name and parameter list
(c) parameter list only (d) return value

15. Which of the following keywords marks the beginning of the function block?
(a) func (b) define (c) def (d) function

16. What is the name given to that area of memory, where the system stores
the parameters and local variables of a function call?
(a) a heap (b) storage area (c) a stack (d) an array

17. Pick one the following statements to correctly complete the function body in
the given code snippet.

def f(number):
# Missing function body
print(f(5))

(a) return "number" b) print(number) (c) print("number") (d) return number

18. Which of the following function headers is correct?


(a) def f(a = 1, b):
(b) def f(a = 1, b, c = 2):
(c) def f(a = 1, b = 1, c = 2):
(d) def f(a = 1, b = 1, c = 2, d):

19. Which of the following statements is not true for parameter passing to
functions?
(a) You can pass positional arguments in any order.
(b) You can pass keyword arguments in any order.
(c) You can call a function with positional and keyword arguments.
(d) Positional arguments must be before keyword arguments in a function call.

20. Which of the following function calls can be used to invoke the below
function definition?
def test(a, b, c, d)

(a) test(1, 2, 3, 4) (b) test(a = 1, 2, 3, 4)


(c) test(a = 1, b = 2, c = 3, 4) (d) test(a = 1, b = 2, c = 3, d = 4)
21. Which of the following function calls will cause Error while invoking the
below function definition?
def test(a, b, c, d)

(a) test(1, 2, 3, 4) (b) test(a = 1, 2, 3, 4)


(c) test(a = 1, b = 2, c = 3, 4) (d) test(a = 1, b = 2, c = 3, d = 4)

22. What is a variable defined outside all the functions referred to as?

(a) A static variable (b) A global variable


(c) A local variable (d) An automatic variable

23. What is a variable defined inside a function referred to as


(a) A static variable (b) A global variable
(c) A local variable (d) An automatic variable

24. Carefully observe the code and give the answer.


def function1(a):
a= a + '1'
a=a*2
>>> function1("hello")

(a) indentation Error (b) cannot perform mathematical operation on strings


(c) hello2 (d) hello2hello2

25. What is the result of this code?


def print_double(x):
print(2 ** x)
print_double(3)

(a) 8 (b) 6 (c) 4 (d) 10

26. What is the order of resolving scope of a name in a Python program?


(L: Local namespace, E : Enclosing namespace, B: Built-In Namespace, G:
Global namespace)

(a) BGEL (b) LEGB (c) GEBL (d) LBEG

27. Which of the given argument types can be skipped from a function call?
(a) positional arguments (b) keyword arguments
(c) named arguments (d) default arguments

Answers 9. a
1. d 10. d
2. c 11. b
3. b 12. a
4. a 13. a
5. d 14. b
6. c 15. c
7. a 16. c
8. b 17. d
18. c 23. c
19. a 24. a
20. a, d 25. a
21. b, c 26. b
22. b 27. D
FILL IN THE BLANKS
1. A set of instructions/operations which is a part of a program and can be executed
independently is called a _____.

2. Python passes parameters by _____.

3. The variable declared outside all the functions is called a _____ variable.

4. The order in which statements are executed during a program run is called the
_____ of execution.

5. A _____ is a file containing Python definitions and statements intended for use in
other Python programs.

6. Functions that do not explicitly return a value return the special object _____.

7. The first line of a function definition is called _____.


8. The function which is written by the programmer as per his/her requirements is
known as _____ function.
9. A function is said to be _____ if it calls itself.
10. _____ act as a means of communication between the called and calling function.

11. The _____ of a variable is the area of the program where it may be referenced.
12. The terminating condition used for solving a problem using recursion is termed as
the _____ for that problem.

13. A _____ is a subprogram that acts on data and often returns a value.

14. Python names the top level segment (main program) as _____.

15. In Python, program execution begins with first statement of _____ segment.

16. The values being passed through a function-call statement are called _____.

17. The values received in the function definition/header are called _____.

18. A parameter having default value in the function header is known as a _____.

19. A _____ argument can be skipped in the function call statement.

20. _____ arguments are the named arguments with assigned values being passed in
the function call statement.

21. A void function also returns a _____ value to its caller.

22. By default, Python names the segment with top-level statements (main program)
as _____.

23. The _____ refers to the order in which statements are executed during a program
run.
24. The default value for a parameter is defined in function _____.
Answers 13. Function
1. function 14. __main__
2. value 15. __main__
3. global 16. argument / actual parameters /
4. flow actual argument
5. module 17. parameter / formal parameter /
6. None formal argument
7. function header 18. default parameter
8. user-defined 19. default
9. recursive 20. keyword
10. Argument / Parameter 21. None
11. scope 22. __main__
12. base class 23. Flow of execution
24. header

TRUE/FALSE QUESTIONS
1. More than one value(s) can be returned by a function in Python.
2. The variable declared inside a function is called a global variable.
3. Once a function is defined, it may be called only once from many different places in
a program.
4. Value returning functions should be generally called from inside of an expression.
5. A local variable having the same name as that of a global variable hides the global
variable in its function.
6. Python passes parameters by reference.
7. Parameters specified within a pair of parentheses in the function definition are the
actual parameters or non-formal parameters.
8. A function in Python is used by invoking it via a function call.
9. Built-in functions are created by users and are not a part of the Python library.
10. The first line of a function header begins with def keyword and eventually ends
with a colon (:).
11. Recursive functions are faster than their iterative counterparts.
12. Recursion is defined as defining anything in terms of itself.
13. Non-default arguments can be placed before or after a default argument in a
function definition.
14. A parameter having default value in the function header is known as a default
parameter.
15. The first line of function definition that begins with keyword def and ends with a
colon (:), is also known as function header.
16. Variables that are listed within the parentheses of a function header are called
function variables.
17. In Python, the program execution begins with first statement of __main__
segment.
18. Default parameters cannot be skipped in function call.
19. The default values for parameters are considered only if no value is provided for
that parameter in the function call statement.
20. A python function may return multiple values.
21. A void function also returns a value i.e., None to its caller.
22. Variables defined inside functions can have global scope.
23. A local variable having the same name as that of a global variable, hides the
global variable in its function.

Answers
1. True
2. False
3. False
4. True
5. True
6. False
7. False
8. True
9. False
10. True
11. False
12. True
13. False
14. True
15. True
16. False
17. True
18. False
19. True
20. True
21. True
22. False
23. True

You might also like