








































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!









































Name of the Chapter-FUNCTIONS IN PYTHON Q NO.
Study the following program and select the possible output : Import random X=random.random() Y=random.randint(0,4) print(int(x),”:”,y+int(x)) a) -1:0 b)1:6 c)2:4 d)0: Function defined in module 2 Select output given by the following code a={i:i*I for I in range(6)} print(a) a) Dictionary comprehension doesn’t exist b) {0:0,1:1,2:4,3:9,4:16,5:25,6:36} c) {0:0,1:1,4:4,9:9,16:16,25:25} d) {0:0,1:1,2:4,3:9,4:16,5:25} Built in function range 3 Choose the correct output of the following Python code: def makenew(mystr): newstr=”” count= for x in mystr: if count%2!=0: newstr=newstr+str(count) else: if x.islower(): newstr=newstr+x.upper() else: newstr=newstr+x count+= newstr=newstr+mystr[:1] print(“The new string is:”,newstr) makenew(“sTUdeNT”) a) ST11111s b) StU1234s c) sT12345s d) sT User defined function 4 Choose the correct output of the following Python code: def ChangeList(): l=[] l1=[] l2=[] for I in range(1,10): User defined function
l.append(i) for i in range(0,1,-2): l1.append(i) for i in range (len(l1)): l2.append(l1[i]+l[i]) l2.append(len(l)-len(l1)) print(l2) ChangeList() a)[11,10,9,8,7,4] b)[11,10,9,8,7,6] c)[11,10,9,8,7] d)[10,9,8,7,6,5] 5 Choose the correct output of the following Python code: def Findoutput(): L=”earn” X=”” L1=[] Count= for I in L: if i in [‘a’,’e’,’I’,’o’,’u’]: X=X+i.swapcase() else: if(count%2!=0): X=X+str(len(L[:count])) else: X=X+i Count=count+ Print(X) Findoutput() a)EArn b)EA3n c)EA 5)EARN User Defined Function and Function defined in module 6 Which output is not expected from the following program: import random X= N=random.randint(1,x) for i in range(N): print (I,”#”,i+1) a)0# b) 1# c)2# d)3# Function defined in module 7 What will be the output of the following Python code?
a is 3 and b is 7 and c is 10 a is 25 and b is 5 and c is 24 a is 100 and b is 5 and c is 50 d) None of the mentioned 10 What will be the output of the following Python code?
14 What will be the output of the following Python code? def display(b, n): while n > 0: print(b,end="") n=n- display('z',3) a) zzz b) zz c) An exception is executed d) Infinite loop User defined function 15 What will be the output of the following Python code? def find(a, **b): print(type(b)) find('letters',A='1',B='2') a) String b) Tuple c) Dictionary d) An exception is thrown Built in function 16 Python passes arguments to function by
27 If the return statement is not used in the function then which type of value will be returned by the function? a) int b) str c) float d) None User defined function 28 Divya wants to print the identity of the object used in the function. Which of the following functions is used to print the same? a) identity() b) ide() c) id() d) idy() in-built functions 29 Function sqrt() is available under which module of python? a. random b. math c. statistics d. None of the above 30 The default value for a parameter is defined in function .....................? a. Definition b. Return statement c. Header d. None of the above 31 Function randint() is available under which module of python? a. random b. math c. statistics d. None of the above 32 ANSWERS Question No Answer (^1) d (^2) d (^3) a (^4) a (^5) b (^6) d (^7) c
(^8) a (^9) c (^10) b (^11) d (^12) b (^13) c (^14) a (^15) c (^16) b.)python passes arguments to function by value (^17) a)Indentation is the blank space in the beginning of a statement within a block (^18) a)Built in functions are predefined functions that are always available for use.For using them we do not need to import any module. For example:len(),type(),int(),input(). (^19) c) recursive function is a function which calls itself (^20) c) scope of a variable is the area of the program where it may be referenced (^21) b) Stack (^22) 2) at end (^23) 2) void function (^24) b)functions (^25) a) (^26) d) (^27) d) (^28) c) (^29) b) (^30) (c) (^31) (a) 32 MCQ BASED QUESTIONS 1 A ______________ is a block of code that will execute only when it is called. a. Function b. Sub Program c. Block d. All of the above Define a function. 2 ________________ is the blank space in the beginning of a statement within a block. a. Indention b. Space c. Body d. None of the above How to write function.
8 By default if you return multiple value separated by comma, then it is returned as a. List b. Tuples c. String d. None of the above. Function returning values 9 Find the output of following code : x= def study(x): global x x= print(“Value of x is :”, x) a. 100 b. 50 c. Error d. None of the above Local and global variables. 10 The values being passed through function-call statement are called ________________. a. arguments b. parameter c. values d. none Function passing values. 11 The values received in function definition/header statement are called ______________. a. arguments b. parameter c. values d. none Function passing values. 12 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 How to return a value by a function.
12 (a) (14, 0) 13 (c) 14 (d) 15 (b) 16 (d) 17 (b) 18 (c) Name of the vetter- INDER PAL SINGH Name of the KV- KV RBNM SALBONI Region-KOLKATA Mobile No- E-mail ID [email protected]
Name of the Chapter-FUNCTIONS IN PYTHON 1 Assertion: The function header ‘def read (a=2, b=5, c):’ is not correct. Reason: Non default arguments can’t follow default arguments. Please choose the correct choice out of the four options given below: a. Both Assertion and reason are true and reason is the correct explanation of assertion. b. Assertion and reason both are true but reason is not the correct explanation of assertion. c. Assertion is true, reason is false. d. Assertion is flase, reason is true. Defining a default argument. 2 A function code is given as follows: def study (num = 5): print(num + 5) Assertion: We can call the above function either by statement ‘study(7)’ or ‘study( )’. Reason: As the function contains default arguments, it depends on the caller that the above function can be called with or without the value. Please choose the correct choice out of the four options given below: a. Both Assertion and reason are true and reason is the correct explanation of assertion. b. Assertion and reason both are true but reason is not the correct explanation of assertion. c. Assertion is true, reason is false. d. Assertion is false, reason is true. Calling a function having default argument. 3 Assertion: len( ), type( ), int( ), input( ) are the functions that are always available for use. Reason: Built in functions are predefined functions that are always available for use. For using them we don’t need to import any module. Please choose the correct choice out of the four options given below: Built in functions.
ANSWERS 1 (a) 2 (a) 3 (a) 4 (c) 5 (c) 6 (c) 7 (b)
DIRECTIONS: In the following questions, A statement of Assertion (A) is followed by a statement of Reason (R). Mark the correct choice as: (A) Both A and R are true and R is the correct explanation for A (B) Both A and R are true and R is not correct explanation for A (C) A is true but R is false (D) A is false but R is true QNO ASSERTION - REASONING LEARNING OUTCOME
4 Assertion(A): It is not possible to delete/remove the elements from a list Reason(R): The pop(), remove(), del() functions are used to remove/delete the elements from the list. Built in function
5 Assertion(A): There are various built in functions/methods to manipulate the dictionaries Reason(R): Built in functions does not work on dictionaries Built in function
Name of the vetter- INDER PAL SINGH Name of the KV- KV RBNM SALBONI Region-KOLKATA Mobile No- E-mail ID [email protected]
4 Aman wants to write a function in python. But he doesn’t know how to start with it! Select the keyword used to start a function out of the following: a) function b) start c) def d) fun ANSWER CBQ NO Answer
MCQ (Multiple Choice Questions) Sl. No Question Learning objectionv 1 A ______________ is a block of code that will execute only when it is called. a. Function b. Sub Program c. Block d. All of the above Define a function. 2 ________________ is the blank space in the beginning of a statement within a block. How to write function.
a. Indention b. Space c. Body d. None of the above 3 Every function return a value if function don’t explicitly return a value, then it will return __________. a. return b. None c. Value d. All How function return values. 4 There are predefined functions that are available in module. For using them we need to import module a. built-in functions b. predefined functions c. user defined functions d. function defined in module Built in functions. 5 The ______________ of a variable is the area of the program where it may be referred. a. external b. global c. scope d. local Local and Global Scope of a variable. 6 Find the output of following code : x= def study(x): x= print(“Value of x is :”, x) a. 100 b. 50 Local and Global Variable