ABS VIDHYA MANDHIR- Tiruvallur
Worksheet
Class: XII
Subject: Computer Science
Topic: Function in Python
1. Function name must be followed by ___________
2. _______ keyword is used to define a function.
3. Function will perform its action only when it is ____________
4. Write statement to call the function.
def Add():
X = 10 + 20
print(X)
_________ #statement to call the above function
5. Write statement to call the function.
def Add(X,Y):
Z = X+Y
print(Z)
_________ #statement to call the above function
6. Which Line Number Code will never execute?
def Check(num): #Line 1
if num%2==0: #Line 2
print("Hello") #Line 3
return True #Line 4
print("Bye") #Line 5
else: #Line 6
return False #Line 7
C = Check(20)
print(C)
7. What will be the output of following code?
def Cube(n):
print(n*n*n)
Cube(n) # n is 10 here
print(Cube(n))
8. What will be the output of following code:
def Alter(x, y = 10, z=20):
sum=x+y+z
print(sum)
Alter(10,20,30)
Alter(20,30)
Alter(100)
9. What will be the output of following code?
def Calculate(A,B,C):
return A*2, B*2, C*2
val = Calculate(10,12,14)
print(type(val))
print(val)
10. What will be the output of following code?
def check():
num=50
print(num)
num=100
print(num)
check()
print(num)
1
11. What will be the output of following code?
def check():
global num
num=1000
print(num)
num=100
print(num)
check()
print(num)
12. What will be the output of following code?
print(“Welcome!”)
print(“Iam“,__name__)
13. Ravi a python programmer is working on a project, for some requirement, he has to
define a function with name CalculateInterest(), he defined it as:
def CalculateInterest(Principal,Rate=.06,Time):
#code
But this code is not working, Can you help Ravi to identify the error in the above function and
what is the solution.
14. What will be the output of following code?
def display(s):
l = len(s)
m=""
for i in range(0,l):
if s[i].isupper():
m=m+s[i].lower()
elif s[i].isalpha():
m=m+s[i].upper()
elif s[i].isdigit():
m=m+"$"
else:
m=m+"*"
print(m)
display("EXAM20@cbse.com")
15. What will be the output of following code?
def Alter(M,N=50):
M=M+N
N=M–N
print(M,"@",N)
return M
A=200
B=100
A = Alter(A,B)
print(A,"#",B)
B = Alter(B)
print(A,’ @ ’ ,B)
16. What will be the output of following code?
def Total(Number=10):
Sum=0
for C in range(1,Number+1):
if C%2==0:
continue
Sum+=C
return Sum
print(Total(4))
print(Total(7))
print(Total())
2
17. What will be the output of following code?
X = 100
def Change(P=10, Q=25):
global X
if P%6==0:
X+=100
else:
X+=50
Sum=P+Q+X
print(P,'#',Q,'$',Sum)
Change()
Change(18,50)
Change(30,100)
18. What will be the output of following code?
a=100
def show():
global a
a=200
def invoke():
global a
a=500
show()
invoke()
print(a)
19. What will be the output of following code?
def drawline(char='$',time=5):
print(char*time)
drawline()
drawline('@',10)
drawline(65)
drawline(chr(65))
20. What will be the output of following code?
def Updater(A,B=5):
A = A // B
B=A%B
print(A,'$',B)
return A + B
A=100
B=30
A = Updater(A,B)
print(A,'#',B)
B = Updater(B)
print(A,'#',B)
A = Updater(A)
print(A,'$',B)
21. Consider the code given below:
b=100
def test(a):
______________ # Missing Statement
b=b+a
print(a,b)
test(10)
print(b)
Which of the following statement should be given in the blank for # Missing statement , if the
output produced is 110?
a) Global a b) global b=100 c) global b d)global a=100
22.
3
23. Write the output of the code given below:
a=30
def call (x) :
global a
if a%2 == 0:
x+=a
else:
x-=a
return x
x=20
print(call(35), end=”#”)
print(call(40),end=’@’)
24. What will be the output of the following code?
def interest(prnc,time=2,rate=0.10):
return (prnc * time * rate)
print(interest(6100,1))
print(interest(5000,rate=0.05))
print(interest(5000,3,0.12))
print(interest(time=4,prnc=5000))
25. Predict the output of the following code fragment?
def func(message, num=1):
print(message * num)
func(‘Python’)
func(‘Easy’,3)