Indian School Al Wadi Al Kabir: Answer The Following

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

INDIAN SCHOOL AL WADI AL KABIR

Class: XII Comp. Sci. Department: Computer Science Date of submission: 09/09/2

Worksheet No: 7 Topic: Python Functions Note:

Answer the following

1.Find the errors in following function definitions :


(a) def main()
print(“Hello”)
(b) def fun2( a*b):
print(a * 2 + b * 5)
(c) def compute()
print(x * x)
(d) Cube(a)
return a * a * a

2.If return statement is not used inside the function, the function will return:
a) 0 b) None Object c) an arbitrary integer d) Error: Functions must have return statement

3.Which of the following keyword marks the beginning of the function block?
a)func b) define c) def d) function

4.What is the difference between the formal parameters and actual parameters? What are
their alternate names? Also, give a suitable Python code to illustrate both.

5.What is the difference between a global variable and a local variable? Also give a suitable
example to illustrate both.

6.From the program code given below, identify the parts mentioned below:
def processNumber(x):
x = 72
return x + 3
y = 54
res = processNumber(y)

7.Trace the following code and predict output produced by it.


1.def power(b,p):
2. y = b ** p
3. return y
4.
5.def calcCube(x):
6. a = power(x,3)

1| 2 9 - 0 8 - 2 0 2 0 / P R E P A R E D B Y : M r . A . R a n j i t h K u m a r
7. return a
8.
9.N = 5
10. Result = calcCube(N) + power(3,3)
11. print(Result)

8.Consider a function with following header:


def info(object, spacing =10, collapse=1):
Here are some function calls given below Find out which of these are correct and which of
these are incorrect static reasons:
a.info(obj1) b. info(spacing=20) c. info(obj2,12) d. info(obj11,object=obj12)
e.info() f. info(collapse=0,obj3) g. info(spacing=15,object=obj4)

9.What will following code print?


def addEm(x,y,z):
print(x+y+z)
def prod(x,y,z):
return x*y*z
a = addEm(6,16,26)
b = prod(2,3,6)
print(a,b)

10. Following code intends to add a given value to global variable a. What will the following
code produce?
1.def increase(x):
2. a=a+x
3. return
4.
5.a = 20
6.b = 5
7.increase(b)
8.print(a)

11. Which names are local, which are global and which are built-in in the following code
fragment?
invaders = “Big names”
pos = 200
level = 1
def play():
max_level = level + 10
print(len(invaders) == 0)
return max_level
res = play()
print(res)

2| 2 9 - 0 8 - 2 0 2 0 / P R E P A R E D B Y : M r . A . R a n j i t h K u m a r
12. Predict the output of the following code fragment?
def func(message, num = 2):
print(message * num)
func(‘Python’)
func(‘Easy’,5)

13. Write User defined function to check whether the input argument is Primer No. or not.

14. Write a user defined functions to find out the No. of values divisible by 5 in a list of
elements passed as an argument.

15. Write a user defined functions to replace all the multiples of 4 as triple of its values in a list
of elements passed as an argument.

16. Write a Python function that checks whether a passed string is palindrome or not.

3| 2 9 - 0 8 - 2 0 2 0 / P R E P A R E D B Y : M r . A . R a n j i t h K u m a r

You might also like