Python Function Test1_answer
Python Function Test1_answer
Ans :
False False False
(a) a
(b) b
(c) def show(a) :
(d) return a
(e) a
(f) b
(g) res=show(b)
(h) res
Ans : (i) a
Ans :
5 Write a menu driven python program using function to do the following: 1. Reverse a 4
Number, 2. Check whether a number is Palindrome or not and 3. To check whether it is
Armstrong or not and 4 to exit. Program should continue till the user says 'no'.
Ans :
6 Find the output of the following code 5
P=100
def changer(P,Q=10):
P=P/Q
Q=P%Q
print(P,"#",Q)
return P
A=200
B=20
A=changer(A,B)
print(A,"$",B)
B=changer(B)
print(A,"$",B)
Ans : 10.0 # 10.0 10.0 $ 20 2.0 # 2.0 10.0 $ 2.0
7 Write a Function Filter() which will take a list as parameter and made the different 5
lists Even[] and Odd[]. And then combine the two list and return the main list i.e.
nested list.
Ans : def filter(L): even=[] odd=[] master=[] for i in L: if i%2==0: even.append(i)
else: odd.append(i) master.append(even) master.append(odd) return master
8 Write a function Common () to accept lists as argument and return the list with 5
common elements from both the lists.
Ans : def common(L1,L2): c=[] for i in L1: if i in L2: c.append(i) return c
9 WAF to take a list and inserting element as parameter and insert the new element at 5
begining of the list.
Ans : def insertbeg(list,n): # Inserting n in the list list = [n] + list[0:]
print("New List",list) # Main li=eval(input("Enter the List"))
ele=int(input("Enter the new element to be inserted")) insertbeg(li,ele)
10 Write a Python program to push all zeros to the end of a given list a. The order of the 5
elements should not change.
Input: Elements of the list with each element
separated by a space.
Output: Elements of the modified list with each
element separated by a space. After the last
element, there should not be any space.
Example:
Input:0 2 3 4 6 7 0 1
Output:2 3 4 6 7 1 0 0
Ans : def pushZerosToEnd(arr, n): count = 0 for i in range(n): if arr[i] != 0:
arr[count] = arr[i] count+=1 while count < n: arr[count] = 0 count += 1 #Main
arr = [1, 9, 8, 4, 0, 0, 2, 7, 0, 6, 0, 9] n = len(arr) pushZerosToEnd(arr, n)
print("Array after pushing all zeros to end of array:") print(arr)
Ans : (c)
14 Which of the following is not correct in context of scope of variables? [CBSE 2021] 1
(a) global keyword is used to change value of a global variable in a local scope
(b) local keyword is used to change value of a local variable in a global scope
(c) global variables can be accessed without using the global keyword in a local
scope
(d) local variables cannot be used outside its scope
Ans : (b)
Ans : (c)
16 Which of the following is not correct in context of Positional and Default parameters 1
in Python functions? [CBSE 2021]
(a) Default parameters must occur to the right of Positional parameters
(b) Positional parameters must occur to the right of Default parameters
(c) Positional parameters must occur to the left of Default parameters
(d) All parameters to the right of a Default parameter must also have Default values.
Ans : (b)
18 What will be the output of the following Python code? [CBSE 2021] 1
V = 25
def Fun (Ch):
V=50
print (V, end=Ch)
print (V, end="*")
Fun ("!")
print (V)
(a) 25*50!25
(b) 50*100!100!100
(c) 25*50!100!100
(d) Error
Ans : (a)
Ans : (c)
21 What is the syntax for creating a function with no parameters or return value? 1
(a) def function_name():
(b) def function_name(parameter):
(c) def function_name() -> return:
(d) def function_name() -> parameter:
Ans : (a)
22 What will be the output of the following Python code? [CBSE 2021] 1
def FunStr(S):
T=""
for i in S:
If i.isdigit():
T=T + i
return T
X = "PYTHON 3.9"
Y=FunStr(X)
print(X, Y, sep="*")
(a) PYTHON 3.9
(b) PYTHON 3.9*3.9
(c) PYTHON 3.9*39
(d) Error
Ans : (a)
23 What will be the output of the following Python code? [CBSE 2021] 1
v = 50
def Change (N):
global V
V, N = N, V
print(V, N, sep="#",end="@")
Change(20)
print(V)
(a) 20#50@20
(b) 50@20#50
(c) 50#50#50
(d) 20@50#20
Ans : (a)
28 Rewrite the following python code after removing any/ all syntactical errors with 2
each correction underlined:
Ans :
39 Write definition of a method ZeroEnding(SCORES) to add all those values in the list 2
of SCORES, which are ending with zero (0) and display the sum.
For example,
If the SCORES contain [200,456,300,100,234,678] The sum should be displayed as
600.
Ans : #Filename:Ch-datas-P_Q10 def ZeroEnding(SCORES): s=0
for i in SCORES: if i%10==0: s=s+i print (s)
41 Write definition of a Method AFIND(CITIES) to display all the city names from a list 2
of CITIES, which are starting with alphabet A.
For example:
If the list CITIES contains
[“AHMEDABAD”,”CHENNAI”,”NEW
DELHI”,”AMRITSAR”,”AGRA”]
The following should get displayed
AHEMDABAD
AMRITSAR
AGRA
Ans : #Filename:Ch-datas-P_Q16 def AFIND(CITIES): for i in CITIES:
if i[0]=='A': print (i)