Working With Functions - Worksheet 3
Working With Functions - Worksheet 3
1. Anish is a student of class XII. During examination, He has been assigned an incomplete python
code (shown below). The code shows the variable scope in a program. Help her in completing the
assigned code.
……. fun(x, y): # Statement-1
………. A # Statement-2
a = 10
x, y = …………. # Statement-3
b = 20
b = 30
c = 30
print (a, b, x, y) # Statement-4
a, b, x, y = 1, 2, 3,4
……………(50, 100) # Statement-5
fun()
print(a, b, x, y) # Statement-6
1. Write the suitable keyword for blank space in the line marked as Statement-1.
2. Write the suitable keyword to access variable a globally for blank space in the line marked as
Statement-2.
3. Write down the python to swap the values of x and y for the blank space in the line marked as
Statement-3.
4. Mention the output for the line marked as Statement-4.
5. The missing code for the blank space in the line marked as Statement-5.
2. Predict the output of the Python code given below: 3. Predict the output
value = 50 L=5
def display(N): B=3
global value def getValue():
value = 25 global L, B
if N%7==0: L = 10
value = value + N B=6
else: def findArea():
value = value - N Area = L * B
print(value, end="#") print("Area = ", Area)
display(20) getValue()
print(value) findArea()
4. Predict the output of the following: 5. Predict the output of the following code? def
p=8 my_func(a=10,b=30):
def sum(q,r=5): a+=20
global p b-=10
p=(r+q)**2 return a+b,a-b
print(p, end= '#') print(my_func(a=60)[0],my_func(b=40)[1])
a=2
b=5
sum(b,a)
sum(r=3,q=2)
6. Predict the output of the following code: 7. Write a function LShift(Arr,n) in Python, which
def f(): accepts a list Arr of numbers and n is a numeric
global s value by which all elements of the list are shifted to
s += ' Is Great' left.
print(s) Sample Input Data of the list
s = "Python is funny" Arr= [ 10,20,30,40,12,11], n=2
s = "Python" Output
f() Arr = [30,40,12,11,10,20]
print(s)
8. Which of the following is not a part of the python function?
(a) function header (b) return statement (c) parameter list (d) function keyword
9. A variable created or defined in a function body is known as…
(a) local (b) global (c) built-in (d) instance
10. For a function header as follows:
def cal(x,y=20):
Which of the following function calls will give an error?
(a) cal(15,25) (b) cal(x=15,y=25) (c) cal(y=25) (d) cal(x=25)
11. In which part of memory does the system stores the parameter and local variables of function
call.
(a) Heap (b) Stack (c) Both a and b (d) None of the above
12. A Function that does not have any return value is known as……………….
(a) Library function (b) Void function (c) Fruitful function (d) None of the above
13. What will be the output of the following code:
def calculate(a, b):
return a+b, a-b
res = calculate(7, 7)
print(res)
(a) (14,0) (b) [14, 0] (c) 14 (d) 0
14. Write a function INDEX_LIST(S), where S is a string. The function returns a list named indexList„
that stores the indices of all vowels of S. For example: If S is "Computer", then indexList should be
[1,4,6]
15. Rewrite the code after removing all the syntactical errors, underlining each correction:
checkval def():
x = input("Enter a number")
if x % 2 == 0
print (x, "is even")
else;
print (x, "is odd")