Functions Worksheet 2024-25
Functions Worksheet 2024-25
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
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.
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)
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)