Worksheet 3 (Working with Functions)
Worksheet 3 (Working with Functions)
(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
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
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()
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
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