# Functions In Python Class 12 Computer Science Important Questions

Students can read the important questions given below for Functions In Python Class 12 Computer Science. All Functions In Python Class 12 Notes and questions with solutions have been prepared based on the latest syllabus and examination guidelines issued by CBSE, NCERT and KVS. You should read all notes provided by us and Class 12 Computer Science Important Questions provided for all chapters to get better marks in examinations. Computer Science Question Bank Class 12 is available on our website for free download in PDF.

## Important Questions of Functions In Python Class 12

Very Short Answer Type Questions :

Question: What is default parameter?
Answer: A parameter having default value in the function header is known as a default parameter.

Question: What is a Library in Python?
Answer: A Library is a collection of modules that together caters to specific types of needs or applications.Like NumPy library of Python caters to scientific computing needs.

Question:. What is module in Python?
Answer: A module is a file with .py extension that contains variables, class definitions, statements and functions related to a particular task.

Question: When is recursion endless?
Answer: An infinite recursion is when recursive function calls itself endlessly.

Question: Is it necessary to have a base case in a recursive function?

Question: What is base case in recursion?
Answer: Preknown case of recursive function, whose solution is pre-known is called base case.

Question: What is recursion?
Answer: Recursion refers to a programming technique in which function calls itself either directly or indirectly. ,

Question: Array for binary search should be sorted or not?

Question: Can a function return multiple values in python?

Question: Consider the following function headers. Identify the correct statement: –
1) def correct(a=1,b=2,c): 2) def correct(a=1,b,c=3):
3) def correct(a=1,b=2,c=3): 4) def correct(a=1,b,c):

Question: Write the features of a module.
Answer: – 1) Modules can be reused in other programmes
2) It is independent group of code and data

Question: Create a package ArithmeticOperations (named AO) contain sum, product and difference of two numbers and use it in your main programme.
return (X+Y)
def PRODUCT(X,Y):
return(X*Y)
def DIFFERENCE(X,Y):
return(X-Y)
Now lets save this file as AO.py then our module is created now.
Now we are creating our main python file: –
import AO
n1=int(input(‘Enter a Number’))
n2=int(input(‘Enter another Number’))
print(‘Difference=’,AO.DIFFERENCE(n1,n2))
print(‘Product=’,AO.PRODUCT(n1,n2))

Question: What will be the output of the following code?
a=1
def f():
a=10
print(a)
Answer: The code will print 1 to the console.

Question: Find the output:
a)
def out(n):
if(n==0):
return
else:
out(n-1)
print(n)
n=6
out(n)
1
2
3
4
5
6
b)
def sum(n):
if(n==1):
return 1
return n*n+sum(n-1)
n=4
print(“Sum is:”,sum(n))
c)
def compute(a,b):
if(b==0):
return a
else:
return compute(a,a%b)
a=6
b=2
c=compute(a,b)
print(“Computer data:”,c)

i. Recursive functions make the code look clean and elegant.
ii. A complex task can be broken down into simpler sub-problems using recursion.
iii. Sequence generation is easier with recursion than using some nested iteration.
i. Sometimes the logic behind recursion is hard to follow through.
ii. Recursive calls are expensive (inefficient) as they take up a lot of memory and time.
iii. Recursive functions are hard to debug.

Question: Write recursive code to compute the factorial of an integer.
def calc_factorial(x):
if x == 1:
return 1
else:
return (x * calc_factorial(x-1))
num = 4
print(“The factorial of”, num, “is”, calc_factorial(num))

Question: Rewrite the correct code after removing the errors: –
def SI(p,t=2,r):
return (p*r*t)/100
Answer: – def SI(p, r, t=2):
return(p*r*t)/100

Application Based Questions :

Question: How many values a python function can return? Explain how?
Answer: Python function can return more than one values.
def square_and_cube(X):
return X*X, X*X*X, X*X*X*X
a=3
x,y,z=square_and_cube(a)
print(x,y,z)

Question: Find the output of the following code: –
n1=n1*n2
n2+=2
print(n1,n2)
CALLME()
CALLME(2,1)
CALLME(3)
2 3
6 4

Question: Predict the output of the following code fragment?
def check(n1=1, n2=2):
n1=n1+n2
n2+=1
print(n1,n2)
check()
check(2,1)
check(3)
3 2
5 3

Question: Write a python program to sum the sequence given below. Take the input n from the user.   img
def fact(x):
j=1 , res=1
while j<=x:
res=res*j
j=j+1
return res
n=int(input(“enter the number : “))
i=1, sum=1
while i<=n:
f=fact(i)
sum=sum+1/f
i+=1
print(sum)

Question: Write a program to compute GCD and LCM of two numbers def gcd(x,y):