function_wk
function_wk
WORKSHEET
1. Name the built-in mathematical function / method that is used to return an absolute value of a number.
2. Find and write the output of the following python code:
def myfunc(a):
a=a+2
a=a*2
return a
print(myfunc(2))
3. What is the default return value for a function that does not return any value explicitly?
4. Name the keyword use to define function in Python.
5. Predict the output of following code snippet:
def function1(a):
a=a+’1’
a=a*2
function1(‘Hello’)
6. Variable defined in function referred to variable.
7. Name the argument type that can be skipped from a function call.
8. Positional arguments can be passed in any order in a function call. (True/False)
9. Which of the following is function header statement is correct.
a. def fun(x=1,y) b. def fun(x=1,y,c=2) c. def fun(a,y=3)
10. Predict the output of following code snippet.
def printDouble(A):
print(2*A)
print(3)
11.Define a function?
12.Write a python function that takes two numbers and find their product.
1. What is the difference between a Local Scope and Global Scope ? Also, give a suitable Python code to illustrate
both.
even ( )
4. Differentiate between Positional Argument and Default Argument of function in python with suitable example
5. 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.
7. What is the meaning of return value of a function? Give an example to illustrate its meaning.
8. Differentiate between call by value and call by reference with a suitable example for each.
10. Rewrite the following code in python after removing all syntax errors. Underline each correction done in the code:
Def func(a):
for i in (0,a):
if i%2 =0:
s=s+1
elseif i%5= =0
m=m+2
else:
n=n+i
print(s,m,n)
func(15)
Application Based Questions (3 Marks)
1. Write a function listchange(Arr)in Python, which accepts a list Arr of numbers , the function will replace the even
number by value 10 and multiply odd number by 5 .
Sample Input Data of the list is:
a=[10,20,23,45]
listchange(a,4)
output : [10, 10, 115, 225]
2. Write a function LShift(Arr,n) in Python, which accepts a list Arr of numbers and
n is a numeric value by which all elements of the list are shifted to left. Sample
Input Data of the list
Arr= [ 10,20,30,40,12,11], n=2
Output
Arr = [30,40,12,11,10,20]
3. Write a function REP which accepts a list of integers and size of list and replaces elements having even values with
its half and elements having odd values with twice its value. eg: if the list contains
3, 4, 5, 16, 9
then the function should rearranged list as
6, 2,10,8, 18
4. Write a function which accept the two lists, and returns a list having only those elements that are common
between both the lists (without duplicates) in ascending order.
Make sure your program works on two lists of different sizes. e.g.
L1= [1,1,2,3,5,8,13,21,34,55,89]
L2= [20,1,2,3,4,5,6,7,8,9,10,11,12,13]
The output should be:
[1,2,3,5,8,13]
5. Write a user defined function countwords() to accept a sentence from console and display the total number of words
present in that sentence.
For example if the sentence entered by user is:
“Living a life you can be proud of doing your best.” then the countwords() function should display the output as:
Total number of words : 11
______________________________________________________________
Q.1) Write a python function that takes two numbers and print the smaller number. Also write how to
call this function.
Q.2) How many values a python function can return? Explain how?
return (p*r*t)/100
Q.4) Write a small python function that receive two numbers and return their sum, product, difference
and multiplication and modulo division.
Q.7) Consider the following function headers. Identify the correct statement: -
n1=n1*n2
n2+=2
print(n1,n2)
CALLME()
CALLME(2,1)
CALLME(3)
______________________________________________
Q.1) What is Libraries in Python and How many types of main library use in Python?
Q.4) Create a function in Python to calculate and return Area of rectangle when user
enters length and bredth.
Q.7) Create a package Arithmetic Operations(named AO) contain sum, product and
difference of two numbers and use it in your main programme.