0% found this document useful (0 votes)
2 views12 pages

Worksheet 3 (Working with Functions)

The document consists of a series of multiple-choice questions related to Python programming concepts, including functions, variable scope, and built-in functions. It covers topics such as the return statement, function headers, memory storage for variables, and the use of docstrings. Additionally, it includes questions about specific code outputs and the behavior of functions in Python.

Uploaded by

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

Worksheet 3 (Working with Functions)

The document consists of a series of multiple-choice questions related to Python programming concepts, including functions, variable scope, and built-in functions. It covers topics such as the return statement, function headers, memory storage for variables, and the use of docstrings. Additionally, it includes questions about specific code outputs and the behavior of functions in Python.

Uploaded by

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

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

(a) print
0 (b) input
1 (c) return
(d) None
Which of the following arguments works with implicit values that are used if
no value is provided?
0 (a) keyword
2 (b) required
(c) variable-length
(d) default
Which of the following items are present in the function header?
(a) function name only
0 (b) both function name and parameter list
3 (c) parameter list only
(d) return value
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
0 (b) storage area
4 (c) a stack
(d) an array
Carefully observe the code and give
the answer.
def function1(a):
a= a + '1'
0 a=a*2
5 >>> function1("hello")
(a) indentation Error
(b) cannot perform mathematical operation on strings
(c) hello2
(d) hello2hello2

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


(a) A static variable
6

1
(b) A global variable
(c) A local variable
(d) An automatic variable
What is a variable defined inside a function referred to as
(a) A static variable
0 (b) A global variable
7 (c) A local variable
(d) An automatic variable
function will return the largest integer less than the given floating
0 point number.
8 a) floor() b) ceil() c) sqrt() d) CEIL()
function returns the absolute value.
a) fabsolute( )
0 b) abs( )
9 c) absolute( )
d) None of these
function returns the length of the object being passed.
1 a) Length() b) Len() c) lenth() d) count()
0
1 A function thon begins with keyword
in py whic ? d) def
1 a) void b) return c) int

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


1
2 a) 9 b) 9.0 c) None d) None of these
What will be the output of the following code:
A=1
def f ():
1
A=10
3
print(A)
a) 1 b) 10 c) Error d) None
What is the value returned by
1 >>> math.floor(-3.4)
4 a) 3 b)-4 c) 4.0 d)3.0

What is the value returned by


1 >>> math.floor(3.4)
5 a) 3 b) 4 c) 4.0 d) 3.0
2
Name the statement that sends back a value from a function
1 a) print b) input c) return d) None
6
What is displayed on executing print(math.fabs(-3.4))?
1 a) -3.4 b) 3.4 c) 3 d) -3
7

3
What is the value of x if x = math.sqrt(4)?
1 a) 2 b) 2.0 c) (2, -2) d) (2.0, -2.0)
8
What is the output of the function shown below (random module has
already been imported)?
1 >>>random.choice('sun')
9 a) sun b) u c) either s, u or n d) Error
function returns the smallest integer greater than the given floating
2 point number.
0
a) floor() b) ceil() c)sqrt() d) abs()
Which of the following function headers is not correct?
a) def f(a = 1, b):
2 b) def f(a = 1, b=3, c = 2):
1 c) def f(a = 1, b = 1, c = 2):
d) def f(a , b = 1, c = 2, d=6):
What is the output of the below
program?
def sayHello():
print('Hello World!')
2 sayHello()
2 sayHello()

a) Hello World! and Hello World!


b) ‘Hello World!’ and ‘Hello World!’
c) Hello and Hello
d) None of the mentioned
What is the output of the below
program?
def printMax(a, b):
if a > b:
print(a, 'is maximum')
2
elif a == b:
3
print(a, 'is equal to', b)
else:
print(b, 'is maximum')
printMax(3, 4)
a) 3 b) 4 c) 4 is maximum d) None of the mentioned
What is called when a function is defined inside a class?
2 a) Module b) Class
4
4 c) Another function d) Method
What is the output of below
program?
2 def f(x, y, z):
5 return x + y + z
f(2, 30, 400)

a) 432 b) 24000 c) 430 d) No output


What is a variable defined outside a function
2 referred to as? a)A static variable b)A global
6 variable
c)A local variable d)An automatic variable

5
What is the output of the following piece
of code?
def a(b):
2 b=b+
7 [5]
c = [1, 2,
3, 4]
a(c)
print(len(
c))
a)4 b)5 c)1 d)An exception is thrown
What is the output of the
following code? def change(i =
1, j = 2):
2 i=i+
8 jj=j
+1
print(i, j)
change(j = 1, i
= 2)
a)An exception is thrown because of conflicting values
b)1 2 c)3 3 d)3 2
What is the output of the below
program? def C2F(c):
return c * 9/5
2 + 32 print
9 C2F(100)
print C2F(0)
a) 212.0 and 32.0 b) 314.0 and 24.0
c) 567 and 98 d) 212 and 32
Which of the following is a features of DocString?
a) Provide a convenient way of associating documentation with Python

3 modules, functions, classes, and methods


b) All functions should have a docstring
0
c) Docstrings can be accessed by the doc attribute on objects
d) All of the mentioned
What is the output of the functions
shown below? ord(65)
3 ord(‘A’)
1 a) A and 65 b) Error and 65
6
c) A and Error c) Error and Error
What are the outcomes of the function shown below?
3 >>>x=3
2 >>>eval('x^2')
a) Error b) 1 c) 9 d) 6
The function pow(x,y,z) is evaluated as:
3 a) (x**y)**z b) (x**y) / z
3 c) (x**y) % z d) (x**y)*z
What is the output of the following
3 function? any([2>8, 4>2, 1>2])
4 a) Error b) True c) False d) 4>2
function can identify the whitespace in a given string.
3
a) Space( ) b) isspace( ) c) Isspace( ) d) is_space( )
5
3 What is the output of the function shown below?
6

7
import math
abs(math.sqrt
(25))
a) Error b) -5 c) 5 d) 5.0
What is the output of the program given below:
import random
x=
3 random.random()
7 y=
random.randint(0,
4) print(int(x),”:”,
y+int(x))
a) 0: 0 b) 2 : 4 c)1: 6 d) 0 : 5
What is the output of the
following code? def display(b,
n):
3 while n > 0:
8 print(b,end
="") n=n-1
display('z',3)
a)zzz b)zz
c)An exception is executed d)Infinite loop
def cal(a,b,c):
return
a*3,b*3,c*3
val=cal(10,12,14)
print(type(val))
3 print(val)
9
a) [30, 24, 28] c) [30,36,42]
d) <class tuple'> and (30,36,42)
b) [10, 20, 30]
What are the outcomes of the function shown below?

4 >>>x=3
0 >>>eval('x**2')
a) Error b) 1 c) 9 d) 6
8
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.
4 2. This variable will not be accessible from anywhere in the prog.
1 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
What is the output of below
program?
4 def say(message, times = 1):
2 print(message * times , end =’ ‘)
say(‘Hello and’)
say('World', 5)

9
a) Hello and WorldWorldWorldWorldWorld
b) Hello and World 5
c) Hello and World,World,World,World,World
d) Hello and HelloHelloHelloHelloHello
What is the output of the below
program? x = 50
def func():
global x
print('x
is', x) x =
2
print('Changed global
x to', x) func()
4 print('Value of x is', x)
3 a) x is 50
Changed global x
to 2 Value of x is
50
b) x is 50
Changed global
x to 2 Value of x
is 2
c) x is 50
Changed global x
to 50 Value of x is
50
d) None of the mentioned
What is the output of the below
program? def func(a, b=5, c=10):
print('a is', a, 'and b is', b, 'and
c is', c) func(3, 7)
func(25, c = 24)
func(c = 50, a =
100)
a) a is 7 and b is 3 and c
4
4 is 10 a is 25 and b is 5
and c is 24
a is 5 and b is 100 and c is 50
b) a is 3 and b is 7 and c

1
0
is 10 a is 5 and b is 25
and c is 24
a is 50 and b is 100 and c is 5
c) a is 3 and b is 7 and c
is 10 a is 25 and b is 5
and c is 24
a is 100 and b is 5 and c is 50
d) None of the mentioned
What is the output of this
program? L = [lambda x: x
** 2,
4 lambda x: x
5 ** 3, lambda
x: x ** 4]
for f in L:
print(f(3))
a) 27 and 81 and 343 b) 6 and 12
c) 9 and 27 and 81 d) None of the mentioned
*********

1
1
1
2

You might also like