0% found this document useful (0 votes)
12 views7 pages

2 Functions Lesson 2

The document contains a series of objective type questions related to Python programming, focusing on functions, parameters, recursion, and variable scope. It includes fill-in-the-blank questions, true or false statements, and multiple-choice questions. Additionally, it provides solved questions that explain the concept of functions and arguments in Python.

Uploaded by

samasadul124
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)
12 views7 pages

2 Functions Lesson 2

The document contains a series of objective type questions related to Python programming, focusing on functions, parameters, recursion, and variable scope. It includes fill-in-the-blank questions, true or false statements, and multiple-choice questions. Additionally, it provides solved questions that explain the concept of functions and arguments in Python.

Uploaded by

samasadul124
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/ 7

OBJECTIVE TYPE QUESTIONS= oeb etetneessetoie tateaeeeteeneaete

1. Fill in the blanks.

(a) A set of instructions/operations which is a part of a program and can be executed independently to
do a specifictask is called a....

(b) Python passes parameters by .


(c) The variable declared outside all the functions is called a. . . variable.
(d) The order in which statements are executed during a program run is called the ..ofexecution.
. .

(e) A . s a file containing Python definitions and statements intended for use in other Python
programs.
(f) Functionsthat do not explicitly return a value return the special object...
(8) The first line of a function definition is called.
(h) The function which is written by the programmer as per his/her requirements is known as .

function.
(i) A function is said to be . . . .. if it calls itself.
G) .. act as a means of communication between the called and calling function.
(k) The... .. of a variable is the area of the program where it may be referenced.
for
(1) The terminating condition used for solving a problem using recursion is termed as the.
that problem.
(m) . . keyword is used to define a function.
(n) Function name must be followed by . . . and
2. State whether the following statements are True or False.
(a) More than value(s) can be returned by a function in Python.
one
(b) The variable declared inside a
function is called a global variable.
cOnce a function is
defined, it may be called only
(a) value returning functions should
once from
many different places
in a program.
be generally called from inside of an expression.
e A Ocal variable having the
function.
same name as that of a global variable hides the global variable in its
() Python passes parameters by reference.
8) Parameters specified within a pair of parentheses in the function definition are the actual
parameters
2.50 or non-formal parameters.
is used by invoking it
Gnction in
A
Python via a function call.
((h) i n functions are created by users and are not a part of the Python library.
i r s t line of a function header begins with def keyword and eventually ends with a colon ()
Recursive functions iterative counterparts.
dre raster than their
acrsion is defined as defining anything in terms of itself.

Function can alter only mutable data types.


Im)
Questions (MCQs)
3. Multiple Choice
in Python begins with which keyword?
(a) A function
(i)void (ii) return (iii) int (iv) def
that sends back a value from a function.
(b) Name the statement
(i) print (ii) input (iii) return (iv) None

c) Functions that do not return any value are known as:


() fruitful functions (ii) void functions
(i) library functions (iv) user-defined functions
(d) A variable created or defined within a function body is classified as:

(i) local (ii) global (ii) built-in (iv) instance

(e) Which of the following arguments works with implicit values that are used if no value is
(iv) default
provided?
(i) keyword ii) required (ii) variable-length
that do notreturn V None
F u n c t i o n s
any value are known as:
(c) i) fruitful functions
(ii) void functions
(ii) library functions
(iv) user-defined functions
Aariable created or defined within a function body is classified as:
(i) local (ii) global (ii) built-in (iv) instance
e)
ahich of the following arguments works with implicit values that are used if no value is provided?
() keyword (ii) required (ii) variable-length (iv) default
a/hich values are used by the functions to communicate information back to the caller?
(i) local (ii) global (ii) return (iv) random
of the program given below?
(a)What is the output
x = 50 padle

def func (x) :


ela
a l e

x = 2

func (x)
print ('x is now x)
()xis now 50 (ii) x is now 2 (ii) x is now 1000 (iv) Error
(h) Which is the most appropriate definition for recursion?
() A function that calls itself
(i) A function execution instance that calls another execution instance of the same function
(ii) A class method that calls another class method
(iv) An in-built method that is automatically called
Fill in the line of code for calculating the factorial of a number:

def fact (num)


if num
==
0:
return l

else:
return
(i) (num-1) * (num-2)
() num*fact(num-1)
(ii) num*(num-1) (iv) fact(num) "fact(num-1)
G) Which of the following statements is false about recursion?
must have base case.
() Every recursive function a

isn't properly mentioned.


() Infinite recursion can occur if the base case

makes the code easier to understand.


) A recursive function
return value.
Every recursivefunction must have a
What is the output of the following snippet?
def fun (n) :
if (n > 100):
return n - 5

eturn fun (fun (n+11)) (iv) Infinite loop


Print (fun (45)) (ii) 74
i)50 (ii) 100
(0) What happens if the base condition isn't defined in recursive programs?
() Program gets into an infinite loop
(i) Program runs once
(ii) Program runs n number of times, where n is the argument given to the function
(iv) An exception is thrown

SOLVED QUESTIONS thsidaNAtabattnntiitii

1. What is function? How is it useful?


a

Ans. A function in Python is a named block of


statements within a program to
For example, the following program has a function within it, perform a
specificC
namely greet_msg ().
#prog1.py
def greet msg ():
print ("Hello there!! ")
name input ("Your name : ")
=

print (name, greet msg ())


Functions are useful as they can be reused anywhere through their function call statements. so, 1or t
same functionality, need not to rewrite the code every time it
one
is needed, rather through Tunctio
it can be used again and
again without rewriting the code.
2. What is an
argument? Give an example.
Ans. An argument is data passed to a function through function call
or
statement. It is also called actual arg
actual parameter. For
example, in the statement
print(math.sqrt(25)) the integer 25 is an aTgum
Chapter2

e ak
(a) function (b) value (c) global (d) flow (e) module
f) None (8) function header (h) user-defined ) recursive
) Arguments/Parameters (k) scope (1) base class
(n) 0,:tcolon) (m) def

(a) True (b) False (c) False (d) True (e) True (f) False a) False (h) True
() Faise 0) True (k) False () True (m) True
olce Qucstions (Mcos)
(a) (iv) (b) (ii) (c) (i) (d) (i) (e) (iv) (f) (ii) (h) (i)
)(iv) (k) (i) (1) (6)

You might also like