(a) A function named LC that accepts two
parameters.
(b) A function named SI that accepts 3
Grade: XII Computer Science(083) parameters p, n, r with values 1000, 5, 0.5
(WorkSheet-02-Functions) 17. Write the flow of execution for the following
I. Answer the following: code:
1. A program with multiple functions is 1. def greet (n):
considered to be better. Why? 2. print(n)
2. Write about (i) Built in functions (ii) 3. enjoy( )
4. def fun (a):
Function in modules with an example to
5. greet (a)
each. 6. def enjoy ( ):
3. What are arguments? What are parameters? 7. print (“Enjoy learning”)
How are these two terms different yet 8. fun (“Learning is fun”)
related? Give example. 18. Rewrite the following program after
4. What do you understand by flow of rectifying errors:
execution? define od#eve (n);
5. Differentiate fruitful and non- fruitful IF n%2=0
print (‘even)
function with an example to each.
else:
6. What all information does a function PRINT (“ODD”)
header give you about the function? OD#EVE [5]
7. What is scope? What is the scope resolving 19. Write the proper function call(s) for the given
rule of Python? function header.
8. When is ‘global’ statement used? Why is def update (L, n = 3):
its use not recommended? 20. Predict the output of the following code:
9. What is the difference between a local v = 50
def change (N):
variable and global variable? Also give a
global v
suitable Python code to illustrate both. v,N = N, v
10. Write the suitable term for the following print (v, N, sep = ‘#’, end = ‘@’)
descriptions: change (20)
i) A value assigned to a parameter name print (v)
in the function call. 21. Predict the output of the following code:
ii) A variable inside a function call. def changelist( ):
11. Explain the parts of the user defined l=[]
l1=[]
function with an example.
l2=[]
12. Explain the different types of parameters for i in range(1,10):
with an example to each. [Link](i)
13. Explain about mutable data type value for i in range(10,1,-2):
passed as an argument to a function with an [Link](i)
example. for i in range(len(l1)):
14. Can a function return multiple values? [Link](l[i]+l1[i])
How? Give proper example in Python. [Link](len(l)-len(l1))
print(l2)
15. Explain the following with an example to
changelist()
each: 22. Predict the output of the following code:
i) A function without ‘global’ keyword. v = 25
ii)A function with ‘global’ keyword. def Fun (ch):
II. Answer the following: global v
16. Write the function header for the following v = 50
statements given: print (v, end = ch)
1
v* = 2 28. def Listchange (L):
print (v, end = ch) for i in range (len (L)):
print (v, end = “ *”) if L[i] % 2 = = 0:
Fun (“ ! ”) L [i] = L[i] * 2
print (v) if L[i] % 3 = = 0:
23. Predict the output of the following code: L[i] = L[i]*3
value = 100 if L[i] % 5 = = 0:
def display (N): L[i] = L[i] *5
global value L = [2, 6, 9, 10]
value = 150 Listchange (L)
if N % 7 = = 0: for i in L:
value = value + N print (i,end = ‘#’)
else: 29. Write a function that accepts a string as its
value = value – N argument and counts displays the no. of
print (value, end = “#”) vowels and no. of consonants separately.
display (50) 30. Write a function Index_List (L) where L is
print(value) the list of elements passed as argument to the
24. Predict the output of the following code: function. The function returns another list
def chkdigit(a, b): named “I_list” that stores the index of all
da = a % 10 numbers divisible by 2.
db = b % 10 Eg. If L contains [3, 4, 16, 7, 9] then “I_ list”
if da < db : should contain [1, 2].
return a 31. Predict the output of the following code:
elif da > db: def alter(p=15,q=10):
return b p=p*q
else: q=p/q
return da, db print(p,’#’,q)
print (chkdigit(603, 279)) return q
25. Consider the following python code and tell a=100
the line(s) have error(s) and rewrite it without b=200
errors. a=alter(a,b)
def display [num] : # L1 print(a,’$’,b)
if num = < 0: # L2
b=alter(b)
print (“negative or zero”)# L3
print(a,’$’,b)
elseif num > 0: #L4
print (“positive of zero”)#L5
a=alter(a,’$’,b)
else: #L6 print(a,’$’,b)
print (“zero”) #L7 32. Predict the possible output(s) from the
call display (2021) #L8 following.
26. Name the modules to be imported for the import random
following functions. AP = [‘red’, ‘green’, ‘yellow’, ‘orange’,
(i) pow ( ) (ii) randrange ( ) ‘blue’, ‘black’]
(iii) mode( ) (iv) uniform( ) P = random. randint (1, 3)
27. Identify the possible output(s) of the Q = random. randint (2, 4)
following code: for i in range (P, Q + 1)
import random print (AR [i], end = ‘- ’)
for N in range (2, 5, 2): (i) black -blue – orange -
print (random. randrange (1, N), (ii) orange – blue-
end = ‘#’) (iii) yellow – orange – blue-
(a) 1 # 3 # 5 (b) 2 # 3 # (iv) green – orange – blue-
(c) 1 # 4 # (d) 1 # 3 #
2
33. Predict the output:
def func(b):
global x
print (“Global” =, x)
y = x+ b
x=7
z=x–b
print (“local x:” , x)
print (“y =”, y)
print (“z =”, z)
x=5
func(10)
34. Write a method AddOddEven(values) to
display the sum of odd and even values
separately from the list of values.
[Link] values=[15,26,37,10,22,13]
The function should display
Even Sum: 58
Odd Sum: 65
35. Write a method Count(id,val) to count and
display the number of times the value of
‘val’ is present in the list ‘id.’
eg. if id=[115,122,137,110,122,113]
and val=122
The function should display 122 found 2
times
36. Write a function FindOut(Names,Hisname)
to search for ‘Hisname’ from a list ‘Names’
and display the position of its presence.
eg. if
Names=[‘Arun’,’Raj’,’Tarun’,’Kannan’]
and Hisname=’Tarun’ then the function
should display ‘Tarun at 2’
37. Write a method Swithover(val) to swap the
even and odd positions of the values in the
list val.
Note: assume the list contains even number
of values in it.
eg. val=[25,17,19,13,12,15]
After swapping the list content should be
displayed as [17,25,13,19,15,12]