WORKING WITH FUNCTIONS
Worksheet-1
1 Which of the following is a valid function name?
a) Start_game() b) start game() c) start-game() d) All of the above
2 If the return statement is not used in the function then which type of value will
be returned by the function?
a)int b) str c) float d) None
3 Richa is working with a program where she gave some values to the function. She
doesn’t know the term to relate these values. Help her by selecting the correct
option.
a) function value b) arguments or parameters
c) return values d) function call
4 What is the minimum and maximum value of c in the following code
snippet? import random
a=[Link](3,5)
b = [Link](2,3)
c=a+b
print(c)
a) 3 , 5 b) 5, 8 c) 2, 3 d) 3, 3
5 In python function, the function calling another function is known as
and the function being called
is known _ _
a) main, keyword b) caller, called
c) called, caller d) executer, execute
6 What will be the output of the following
code? print(“100+200”)
a) 300 b) 100200 c) 100+200 d) 200
7 pow( ) function belongs to which library ?
a) math b) string c) random d) maths
8 What data type is the object below?
L = (1, 23, ‘hello’,1)
a) list b) dictionary c) array d) tuple
9 What is returned by int([Link](3, 2))?
a) 6 b) 9 c) error, third argument required d) error, too many arguments
10 Which of the following is not a type conversion functions?
a) int() b) str() c) input() d) float()
11 Write the output of the following:
print(float())
12 Identify the module to which the following function load () belong to?
a) math b) random c) pickle d) sys
13 How many argument(s) a function can receive
a) Only one b) 0 or many c) Only more than one d) At least one
14 Give the output
def fun():
global a
a=10
print(a)
a=5
fun()
print(a)
a) 10 b) 5 c) 5 d) 10
10 10 5 5
15 Value returning functions should be generally called from inside of an expression
a) True b) False
16 The variable declared inside the function is called a variable
a) global b) local c) external d) none of the above
17 These are predefined functions that are always available for use. For using them
we don’t need to import any module
a) built in function b) pre-defined function
c) user defined function d) none of the above
18 The of a variable is the area of the program where it may be referenced
a) external b) global c) scope d) local
19 If you want to communicate between functions i.e. calling and called
statement, then you should use
a) values b) return c) arguments d) none of the above
20 Which of the following function header is correct?
a) def mul(a=2, b=5,c) b) def mul(a=2, b, c=5)
c) def mul(a, b=2, c=5) d) def mul(a=2, b, c=5)
21 Find the flow of execution of the following code:
1. def calculate (a, b):
2. res=a**b
3. return res
4.
5. def study(a):
6. ans=calculate(a,b)
7. return ans
8.
9. n=2
10. a=study(n)
11. print(a)
a) 1 > 5 > 9 > 10 >6 > 2 > 3 > 7 > 11 b) 5 > 9 > 10 > 6 > 2 > 3 > 7 > 11
c) 9 > 10 > 5 > 1 > 6 > 2 > 3 > 7 > 11 d) None of the above
22. Python resolves the scope of a name using the LEGB rule
a) True b) False
23 A void function internally returns legal empty value
a) None b) Close() c) Return d) all
24 When you use multiple type argument in function, then default argument take place
a) at beginning b) at end c) anywhere d) none of the above
25 A can be skipped in the function call statements
a) named parameter b) default parameter
c) keyword parameters d) all of the above
Worksheet-2
functions
QUESTIONS
1. What is the output of the following code?
def cube(x):
return x * x * x
x = cube(3)
print( x)
a) 9 b)3 c)27 d) 30
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
3 Choose correct answer
def fun1(num):
return num+5
print(fun1(5))
print(num)
a) Print value 10 b) Print value 5 c) Name Error d) 25
4. Predict the output of the following code
def func1(list1):
for x in list1:
print([Link](),end="#")
func1(["New","Dehli"])
A. [New,Dehli]
B. new#dehli#
C. newdehli#
D. New#Dehli#
5. What will be the output of the following python code?
def mul (num1, num2):
x = num1 * num2
x = mul(20,30)
A. 600 B. None C. No Output D. 0
6 Which of the following function header is Correct:
A. def fun(x=1,y)
B. def fun(x=1,y,z=2)
C. def fun(x=1,y=1,z=2)
D. def fun(x=1,y=1,z=2,w)
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 Choose the correct output from the options given below.
print(‘Welcome!’)
print(‘Iam’, name ) # is double underscore
a) Welcome! b) Error
Iam __main
c) Welcome! d)None of these
Iam __name
9 Predict the output of the following code
fragment def update(x=10):
x+=15
print("x=",x)
x=20
update()
print("x=",x)
a) x=20 b) x=25
x=25 x=25
c) x=20 d) x=25
x=25 x=20
10 Predict the output of the following code
fragment def display(x=2,y=3):
x=x+y
y+=2
print(x,y)
display( )
display(5,1)
display(9)
a) 5 5 b)12 5
63 63
12 5 55
c) 5 6 d) 5 5
12 5 7 7
63 6 6
11 Find the output print(pow(5,4,9))
a) 7 b)0 c)4 d) error
Give the output of the following program
12 def check(a):
for i in range(len(a)):
a[i]=a[i]+5
return a
b=[1,2,3,4]
c=check(b)
print(c)
a) [6, 8, 8, 9] b) [6,7,8,9]
c) [7, 7, 8, 9] d) [6,7,9,9]
13 Give the output
def abc(x,y=60):
return x+y
a=20
b=30
a=abc(a,b)
print(a,b)
b=abc(a)
print(a,b)
a=abc(b)
print(a,b)
a) 50 30 50 110 170 b) 30 50 110 170 110
c) 50 30 d) 50 30 50 110 170 110
50 110
170 110
14
Predict the output of the following code snippet:
def Execute(M):
if M%3==0:
return M*3
else:
return M+10;
def Output(B=2):
for T in range (0,B):
print(Execute(T),"*",end="")
print()
Output(4)
Output()
Output(3)
15. Find the output of the following program:
def ChangeIt(Text,C):
T=""
for K in range(len(Text)):
if Text[K]>='F' and Text[K]<='L':
T=T+Text[K].lower();
elif Text[K]=='E' or Text[K]=='e':
T=T+C;
elif K%2==0:
T=T+Text[K].upper()
else:
T=T+T[K-1]
print(T)
OldText="pOwERALone"
ChangeIt(OldText,"%")
(a) PPW%RRLLN% (b) PPWCRRllNC
(c) PPW%RRllN% (d) PpW%RrllN%
16 What possible outputs are expected to be displayed on screen at the time of execution
of the program from the following code? Also specify the maximum value that can be
assigned to each of the variables L and U.
import random
Arr=[10,30,40,50,70,90,100]
L=[Link](1,3)
U=[Link](3,6)
for i in range(L,U+1):
print(Arr[i],"@",end="")
i) 40 @50 @ ii) 10 @50 @70 @90 @
iii) 40 @50 @70 @90 @ iv) 40 @100
@
17 Find the output of the following code
def disp(str):
m=' '
for i in range(0,len(str)):
if(str[i].isupper()):
m=m+str[i].lower()
elif str[i].islower():
m=m+str[i].upper()
else:
if i%2==0:
m=m+str[i-1]
else:
m=m+"@"
print([Link]())
disp('StudyBag$2021')
a) StudyBagG@2@2 b) sTUDYbAGg@2@2 c) StudyBagG$2$2 d) None
18 What will be the output of the following code
total=0
def add(a,b):
global total
total=a+b
print(total)
add(6,6)
print(total)
a) 12 b) 12 c) 0 d) None of these
12 0 12
19 Find and write the output of the following Python code:
def makenew(mystr):
newstr = " "
count = 0
for i in mystr:
if count%2 ==0:
newstr = newstr+[Link]()
else:
if [Link]():
newstr = newstr+[Link]()
else:
newstr = newstr+i
count +=1
newstr = newstr+mystr[:3]
print ("The new string is :", newstr)
makenew("cbseEXAMs@2022")
20 What possible output(s) are expected to be displayed on screen at the time of
execution of the following code? Also specify the maximum and minimum value that
can be assigned to variable X.
import random
L=[10,7,21]
X=[Link](1,2)
for i in range(X):
Y=[Link](1,X)
print(L[Y],"$",end=" ")
(i)10 $ 7 $ (ii) 21 $ 7 $ (iii) 21 $ 10 $ (iv) 7 $
21 Choose the correct option:
Statement1: Local Variables are accessible only within a function or block in which it
is declared.
Statement2: Global variables are accessible in the whole program.
a. Statement1 is correct but Statement2 is incorrect
b. Statement2 is correct but Statement1 is incorrect
c. Both Statements are Correct
d. Both Statements are
incorrect
22 Consider the following code and choose correct answer:
def nameage(name, age):
return [age,name]
t=nameage('kishan',20)
print(type(t))
a) tuple b) list c) (kishan,20) d) None of all
23 Write the output of the following:
a=(10, 12, 13, 12, 13, 14,
15)
print(max(a) + min(a) + [Link](2))
a) 13 b) 25 c) 26 d) Error
24 Consider the code given below and Identify how many times the message “Hello
All” will be printed.
def prog(name):
for x in name:
if [Link]():
print('Alphabet')
elif [Link]():
print('Digit')
elif [Link]():
print('Capital Letter')
else:
print('Hello All')
prog('vishal123@[Link]')
a) 0 b) 2 c) 1 d) 3
25 Find and write the output of the following Python code:
def changer(p,q=10):
p=p/q
q=p%q
print(p,"#",q)
return p
a=200
b=20
a=changer(a,b)
print(a,"$",b)
a=changer(a)
print(a,"$",b)
26 What will be the output for the below code snippet?
def div(lst,n):
for i in range(0,n):
if lst[i]%5==0:
lst[i]+=5
else:
lst[i]=lst[i]//2
lt=[45,20,23,54,5]
div(lt, len(lt))
for i in lt:
print(i,end='#')
a) 50#25#11.5#27.0#10# b) 50#25#11#27#10#
c) 50#25#1#0#10# d) 225#100#1#0#25#