2
Which of the following is true about the use
of id() function in python?
(a) Idreturns the identity of the object
(b) Every object doesn't have a unique id
(c) All of the mentioned
(d) None of the mentioned
What will be the output of the following
code
print type(type(int))
(a) type ‘int’ (b) type ‘type’
(c) Error (d) null
What is the output of the function
len({"hello”,2,4,6])
(a) 4 (b) 3
() Error (6
What will be the output of the following
code?
import math
abs (math. sqrt(25))
(@ 5
(c) error
(6) 5.0
(d) No output
What is the output of the functions shown
below?
min(max(False, -13,~4),2,7)
(a) -13 (6) 4
(0) Tre (A) False
|. What is a variable defined outside a function
referred to as?
(@ Asiatic variable
(b) A global variable
(©) A local variable
(d) An auto variable
12,
What is a variable defined inside a function
referred to as?
(a) A global variable
(b) A static variable
(c) A local variable
(d) None of the mentioned
Ifa function doesn't have a return statement,
which of the following values does the
function will return?
(a) int
(6) null
(c) None
(d) An exception is thrown without the
return statement
Which keyword is used to denote the exit
of a function block?
(a) def (b) exit
(c) return (d) finally
Which of the following functions accepts
only strings as arguments?
(a) ord() (6) chr)
(c) min() (d) max)
What is the output of the function:
def sum()
calculate()
def calculate():
x = int(14.5)
y = float (24.6)
sexty
print("%d" %s)_
sum()
(a) 38.1 (6) 38.0
(© 37 (@ 38
Predict the output of the followin;
def addition(j):
if (j >= 4):
Jeeia' a)
else:
Computer Science with Python 65deny 2
return j
deh
a = add(i)
print("8d” %a)
@ 16 (8) 8.0
4 @ 16.0
13, Give the output of the following program:
def function(b) :
xb*D
return x
for i in range(1, 6):
a = function(i)
print("td" %a, end=" “)
(@) 144 (6) 120
(o) 25 @ 36
14, Write the output of the following code:
def area(a):
return (a * a)
def areai(1, b):
return (1 * b)
al = area(4)
print ("%d"%a1)
a2 = areal(5,6)
print ("%d"%a2)
(a) 16 (b) 4
30 30
(0 5 (d) None of these
6
15. Predict the output:
i= 100
def abc():
i= 10
print ("first = %d" %i)
def main( ):
i-2
abc()
print("Second = %d" %i)
main()
(a) first=10 (6) first-100
second=100 second=2
© first=10 @ first=100
second=2 second=100
16. Tell the output of the fo}
fragment:
a=3
lowing
def fun1_demo(x, y, 2)
as3
azas+ (x+y)
zeary
Yeas
bes
funt_demo(a, a, b)
print("Xd %d 2d" X(a, a, ))
@794 O225
G35 @753
17. Choose the correct answer for
code snippet “ne
def max(x, y, z):
if(x > y and y > 2):
yeyea
eect
return x
else
if (y > x):
return y
else
return 2
a, b, c= 10, 13, 8
a = max(a, b, c)
Print ("td d 2d" &(a,
b = max(a, b, c)
print ("td %d Rd" %(a+1, bel, ced))
¢ = max(a, b, c)
print("%d d Xd" %(a-1, b-2, ¢-1))
c))
@B3 B 8 @®0 Bs
149 9 149 9
12.7 ae 12: Fim
(©) 13 10 8 — (d) None of these
14 11 10
13458 a9
6 — agcoher eced® Competency Based and Objective Type Questions —1218. Write the output of the following program :
def Cale (U):
if (U%2 == 0):
return U + 10
else:
return U* 2,
def Pattern (M, B = 2) ;
for CNT in range(0, 8)
print( M * (Calc(cNT)))
Pattern(*A", 2)
(@ AAAAA
AA
(6) AAAAAAAAAA
AA
(c) AAAAAAAAAA
AAAA
(d) None of these
19. What will be the output of the following:
def cubic(x)
return x*x*x
print (cubic(5)
(a) 120
(b) 128
(c) 136
(@) An error is displayed
20. Predict the output, ifn! = 50, n2= 10
def add(mi, m2):
return(il - m2)
nd=int (i Enter the number ni: *))
n2=int(input("Enter the number n2 + *))
result = add(n1,n2)
print("%d" % result)
(a) 60 (6) 40
© 30 (@ 20
21. What will be the output of the following
def func(x, y=10):
return x,y
a,b, c=11,12,13
print (func(11,12))
@ (1 12)
(c) (0 11)
(&) (10 12)
(@ none of these
22. State the output of the following code
snippet:
x=20
def func():
global x
x=25
func()
x5
print
(a) 20
(5
(®) 25
(d) None of these
23, Which of the following keyword is the
correct way to define the function test(): ?
(a) def test() (6) pass test()
(0) define test (d) while test()
24, Ifa function is defined as:
def check(a,b,c)
and function call is
check(2,a,b)
check(a,2,a)
check(2,a,2)
Then this way of argument specification is
called
(@) positional argument
() default argument
(©) named argument
(@ none of these
25, Write the output of the following:
def Max(a, b)
if a>b:
print(a, ‘is maximun’)
elif a =
print(a,
else:
is equal to’, b)
print(b, ‘is maximum’)
Max(4, 4)
(a) 4is equal to4 (6) 4=4
(©) 4s maximum (d) none of these
Computer Science with Python 6726. Write the output of the following:
def func(mesg, num=1):
print (mesg*nun)
func ("welcome")
fune(*wel”,3)
(@ welcome
welwelwel
() welcome
(© welcome
wel
(@ None of the above
27, Tell the output of the following:
myvar = §
def printvar() :
print (myvar)
printvar()
(a) 01245 (8) 12345
©s (@ 1234
28. What is printvar in the following statements?
myvar = 5
def printvar() :
print (type(nyvar))
printvar()
(a) Alist (6) Astring
(©) Aninteger (a) A function
29, What will be the output after the following
statements?
myvar = 8
def printvar() :
print (myvar, end =")
printvar()
printvar()
@ 8 (5) 88
8 (d) None of these
30. What will be the output after the following
statements?
def call(var)
print(var, end ='')
call (45)
(@ 35 (45
© 45 @ var
G8 Pagechex aed? Competency Based and Objective Type Questions —12
3.
32.
33.
34.
35.
36.
‘What will be the output ater the
statements?
def call(vart, var2) ;
print(varl + var2, eng ¢+,
call (10, 40)
(@ 10 (6) 50
(©) 40 @ 10+49
Write the output of the following
def call(varl, var2, vara) ;
print (vari var2 var3, eng
return value.
(©) Using from statement, a specific (0) Function with no argument and with
function is imported from a module areturn Valle
(@ Whatever times a module is imported, (©) Python Function with argument and
it is loaded only once. no return value.
Options are (@ Function with argument and return
value.
(i only (@)
iy Band (©) 80. Predict the output of the following:
(ii) only (6) and (c aot Maree)
(iti) all the three (a), (b) and (c) wae
(iv) All of the above print (a, ‘is maximum’)
ae int? elif a
16. ing code will print? fa
else:
print(b, ‘is maximum’)
: Max (13, 24)
ee p (@) 13 (6) 24 is maximum
16,
y-prod(2,3,6) (©) 24 (d) Noneoftheabove
icy) 81. Which of the following is the use of id()
(@ 47 36 funetion in python? :
‘47 (a) Id returns the identity of the object
NeeesG (b) Every object doesn't have a unique id
(© 36 (0) All of the mentioned
(d) None of the above (@) None of the mentioned
Computer Science with Python 7382. What will be the output ofthe following code :
print type(type(int))
(a) type ‘int’ (6) type ‘type’
(©) Error (@ null
‘83. What is the output of the function:
Jen(["*hello",2,4,6])
@4 (6) 3
(©) Error @6
84. What will be the output of the following
code?
import math
abs(math. sqrt (25) )
@ 5 (b) 5.0
(©) error
(@ No output
85. What is the output of the functions shown
below?
min(max(False, -3,-4),2,7)
(a) 3 () 4
(©) True (d) False
Assertion-Reasoning Type MCQs
Directions: The following questions consist of two
statements, one labelled as the ‘Assertion (A)’ and
the other as “Reason (RY’. You are to examine these
wo statements carefully and select the answers
using the code given below:
(@) Both A and R are individually true and R is
the correct explanation of A
() Both A and R are individually true but Ris
not the correct explanation of A
(©) Ais true but R is false
(@) Ais false but R is true
89. Assertion (A): Function red
length.
luces the code
74
86.
87.
88.
90.
a.
Tagethecr with? Competency Based and Objective Type Questions—12
What is a variable defined
referred to as?
(a) A static variable
(6) A global variable
(©) A local variable
Outside a fy
(@) An auto variable
What is a variable defined inside
referred to as?
(@) A global variable
(6) A static variable
(©) A local variable
(@) An auto variable
Ifa function doesn't have a return sta
which of the following does the fi
return?
(a) int
(© null
(c) None
(@ An exception is thrown without
retum statement
Reason (R): Advantage of function is thay
same code is not required to
multiple places in a program.
Assertion (
be written at
'A): Function can be defined asa
named group of instructions that accomplish
4 specific task when it is invoked,
Reason (R): Once defined, a function cannot
be called repeatedly from different placesof
the program without writing all the codes of
that function e
Assertion (A): There are broadly 196
Categories of functions
Reason (R): The programmer can defineas
many functions as desired while writing the
code,Assertion (A): Bulky
avoided using functions,
Reason (R): Programs can
using functions,
Programs can be
only be written
93. Assertion (A)
User defined functions can
where without defini
Reason (R): No need to defi
library functions,
Assertion (A): To find maxim
ofa list max() is used.
be invoked any es
ine standard
um element
Reason (R): max() calculates the maximum.
: 98,
element in a sequence,
95.
Assertion (A): User defined functions
always returns a value
Reason (R): Default return value of a
function is None.
Assertion (A): Functions in Python can
Teturn multiple values.
Reason (R); Broadly, in Python there are
‘Wo types of functions.
Assertion (A): Functions helps to break our
Program into smaller and modular chunks.
Reason (R): Python avoids repetition and
makes the code reusable.
Assertion (A): In Python, there are 68 built-
in functions,
Reason (R ): Functions are an essential part
of the Python programming language.
Case-Based MCQs
1, The ABC School Management has
Promotion rule/salary increment. He wrote the fo
code, answer the following question.
def show(P,£)
if P.upper()
if E>=30:
GT
Print("No further upgradation as Teacher")
elif E>=20 :
Print ("one more seniority grade
elif E>=10:
print("One seniority Grade ")
else :
print("You will get normal increment")
Given a task to Mr. Amit Anand to write the code for the
lowing code using function. On the basis of
# Statement 1
# Statement 2
# Statement 3
# Statement 4
elif P.upper()=="T6
if +20
print("Salary is upgraded to PGT Level”) # Statement 5
elif f>=10
print ("One seniority Grade and eligible as PGT ") # Statement 6
else :
print("You will get normal increment”) # Statement 7
else :
print("Please enter correct data")
# Statement 8
Computer Science with Python = 75Post = input("Your post as PGT/TGT ")
Experience = int(input("No of years : *))
shou(Post, Experience)
(a) Which statement will be executed if Post = “Pgt” and experience = 157 :
( Statement 1 (ii) Statement 2 (ii) Statement 3 (iv) Statement g
(®) Which statement will be executed if Post = “Vice Principal” and experience ~ 159
(@ Statement 2 (ii) Statement 4 (iii) Statement 6 (iv) Statement g
(c) Which statement will be executed if Post = “tgt” and experience = 5?
( Statement 5 (ii) Statement 6 (iii) Statement 7 _(iv) Statement g
(@) Which statement will be executed if Post = “tgt” and experience = 22?
(H Statement 5 (i) Statement 6 (iii) Statement 7__(iv) Statement g
(€) Which statement will be executed if Post = “Pet” and experience = 15?
(H Statement 1 (i) Statement 2 (iii) Statement 3 (iv) Statement 4
2, Indian Law Organization is planning to computerized their application form. For regi
organization has setup the rules imposed by Indian Law. Citizen can check their eligibility
by providing Nationality, Gender and Age.
def show(N,G,A):
if N.upper() in “INDIAN, INDIA’
if G in "MALE,M" +
if A>=21:
print ("You are eligible for Marriage °)
else =
print("You are underage ")
elif G in “FEMALE ,F*:
if #18:
print(*You are eligible for Marriage ") * Statement 3)
else :
# Statenent
® Statenent.
print("You are underage ")
else :
print ("Please follow your own country rules. *)
Nationality = input("Nationality : “)
Gender = input("Gender (H/F): *)
Age = int(input("Age : *))
show (Nationality, Gender, Age)
On the basis of above code, choose the best appropriate option.
(a) Which statement will be executed if Nationality is Indian, Gender is Male and Age is 19.
(@ Statement 1 (ii) Statement 2___(iii) Statement 3 _(iv) Statement 4
(6) Which Statement will be executed, if Nationality is American, Gender is Female and Ageis 27.
(O Statement 1 (ii) Statement 2
(iii) Statement 4 (iv) Statement 5
(©) Which Statement is executed, if Nationality is Indian, Age is 25 and Gender if Female.
(@ Statement 1 (ii) Statement 2 (iii) Statement 3 _(iv) Statement 4
Fegecher wach? Competency Based and Objective Type Questions —12(@ Which Statement is executed, if Nationality is Indian, Age is 17 and Gender is Female,
(@ Statement 1 (i) Statement 2 (iii) Statement 3. _(iv) Statement 4
(©) Which statement will be executed if Nationality is Indian, Gender is Male and Age is 29.
(@ Statement 1 (ii) Statement 2
(iii) Statement 3 (iv) Statement 4
3. ABC School offered Stream to their students on the basis of following criteria. Programmer wrote
the following code.
0 Medical
>=15 >=85 5 Non-Medical
>=75 >=60 5 Commerce with Maths
>=60 >=60 0 ‘Commerce without Maths
>=50 >=45 >=50 Humanities Stream
Otherwise Vocational Stream
def Check(M,S,A)
if M>=80 and S>=90 and A>=90 :
print("Eligible for Medical Stream ") # Statement 2
elif M>=75 and S>=85 and A>=85 :
print("Eligible for Non-Medical Stream") # Statement 2
elif M>=75 and S>=60 and A>=75
print("Eligible for Commerce with Mathematics Stream") # Statement 3
elif M>=60 and S>=60 and A>=60 :
print("Eligible for Commerce without Mathematics Stream") # Statement 4
elif M>=50 and S>=45 and A>=50 :
print("Eligible for Humanities Strean*) & Statement 5
else :
print("Eligible for Vocational Stream") # Statement 6
Math = int(input("Enter Mathematics Marks :"))
Sci = int(input("Enter Science Marks :"))
Avg = int(input("Enter Average Marks :"))
Check(Math, Sci, Avg)
Choose the correct possible option on the basis of following code.
(a) Which Statement will be executed, If a Student scored marks as Maths = 75, Science = 80
and Average = 89.
() Statement 1 (ii) Statement 2 (tif) Statement 3 (iv) Statement 4
(6) When a Student is Eligible for Humanities Stream?
( Student scored marks as Maths less than 65, Science = 80 and Average = 89.
(ii) Student scored marks as Maths = 75, Science = 80 and Average = 89.
(iii) Ifa Student scored marks as Maths = 55, Science = 47 and Average = 55.
(iv) Ifa Student scored marks as Maths = 75, Science = 80 and Average = 89.
Computer Science with Python 77(©) Which Statement will be executed, If a Student scored marks as Average = 65,
and Maths = 80.
( Statement 3 (i) Statement 4 (iii) Statement Sv) Statement g
(@) Which Statement will be executed, if a Student Scored marks in Science = 35, yy.
and Average = 41.
(i) Statement 3 (ii) Statement 4 (ii) Statement 5
(€) Which Statement
Average = 65.
(H Statement 4 (ii) Statement $__ (iii) Statement 3 (iv) Statement g
Mohan is a programmer, he has written the following program to calculate the cost of
different shapes of bags.
#Program to calculate the cost of different bags
#function definition
def cyl(h,r):
area_cyl = 2°3.14*rth #Area of cylindrical part
return(area_cyl)
function definition
def con(1,r):
‘area_con = 3.14*r*l #Area of conical part
xeturn(area_con) #line 1
‘function definition
def post_tax price(cost): #compute payable amount for the tent
tax = 0.48 * cost;
net_price = cost + tax
return(net_price) Line 2
print("Enter values of cylindrical part of the bag
h = float(input("Height: "))
x = float(input("Radius: "))
csa_cyl = cyl(hyx) sfunction call
1 = float(input("Enter slant height of the conical bag in
csa_con = con(1,r) Line 3
SCalculatethe area of the canvas used for making the
canvas_area = csa_cyl + csa_con
print("Area of canvas = “,canvas_area,” m°2")
#Calculate the cost of canvas
unit_price = float(input("Enter cost of 1 m2 canvas in 1
total_cost = unit_price * canvas_area
print(*Total cost of canvas before tax = ",total_cost
print(*Net amount payable (including tax) = ",post_tax_price(total_cost))
(a) Mohan’s friend, Madan saw the code and he is bit unclear on the use of return statement
function definition. Help him in understanding
(1) It shows the end of the execution of a function
(I) returns control to the calling function.
(iv) Statement 5 —
ill be excouted, Ifa Student Scored Science = 66 , Maths ~ gy
(QI) A retum statement can retum a value to the calling function
“Jegether coteh® Competency Based and Objective Type uestions—125.
(IV) python function will always have a retum value
Tell him which of the above statement is true.
© (1) only (ii) (1) and (11) only
(iii) ®, (II) and (111) (iv) All the four statements are true
(b) The default return value for a function in python is:
(i) integer
(ii) float (iii) Complex (iv) None
(c)_ What is the return datatype of the function post tax price() in #Line 1?
(i) integer (ii) float (iii) Complex (iv) None
@ ps! as return data type of the function con(I,r) ,if | and r are both integer types in
ine
(i) integer (ii) float (iii) Complex (iv) None
(e) Madan changed the code in Line number 3 to as shown below:
csa_con con(1=10,r) #Line 3
Will there any change in the function ?
(i) no change (ii) function result
be affected
(iv) None of the mentioned
Shreya has written a calculator program for her assignment.
# Program to make a simple calculator
(ili) Syntax error will be displayed
# This function adds two numbers
def add(x, y)
return x + y
# This function subtracts two numbers
def subtract(x, y):
return x - y
# This function multiplies two nunbers
def multiply(x, y):
return x * y
# This function divides two numbers
def divide(x, y)
return x * y
print("Select operation.")
print ("1.Add"
print("2.Subtract")
print ("3.Multiply")
print("4.Divide”)
while True:
# Take input from the user
Computer Science with Python = 79choice = input(“Enter choice(1/2/3/4): *)
# Check if choice is one of the four options
if choice in (‘1', ‘2’, °3’, 4’):
mud = float(input("Enter first number: “))
nun2 = float(input("Enter second nunber: *))
if choice =:
print (num, ", add(numd, nue2))
elif choice =
print (num, 2", subtract(numl, num2))
elif choice
print(numl, "*",
"=", multiply(nund, m
5
elif choice
print(numi,
break
else:
print ("Invalid Input”)
(@) Mridula, Sriya’s friend did not undetstand the concept of function parameter and
arguments. Help her in understanding the code. She spoke the following statements
Parameters and arguments
I. Function parameters are the named lists in the function's defi
inction
fivide(nunt, nun2))
inition.
IL Function arguments are the real values passed to
IIL, Parameters are initialized to the values of the a
IY. Parameters in the function call are called as f
Which of the above statement is correct?
( only I true (i) only I and Il are true
(iii) statement I, II and III are correct (iv) All the four statements are correct
(6) Further, Mridula changed the function call in the statement, add(numl, mu
aded(num!=10,num2)
Will the program run?
(@ yes
(iit) can't say
() Again, she changed the function call statement add(num = 10, num?) to add(num!=10;
Will the program run?
nts supplied
rameters
(ii) Error will be occurred
(iv) None of the above
(ii) Error will be occurred
@ yes
(iii) can’t say (iv) None of the above
(d) What are the type of arguments used in the python function?
@1 (i 2 (iii) 3 (4
80 —Fagecher with” Competency Based and Objective Type Questions —12in python functi
(formal paraménters Function?
(iii) positional arguments iB Rs Parameters
ject i is fri ‘eyword arguments
& Manet is codes, his fend Ramesh told him 4 write a user defined function trafficLight( )
that accepts input from the use ; t poe
these three colour. ‘message, if the user enters anything other
(@) Tell which of the following fun,
(O det traftictight()
*, displays an error
ction code is correct?
colors= ("RE YELLOW", "GREEN")
if (signal not in colors):
Print((
"Please enter a valid Traffic Light colour in CAPITALS")
signal1 = input(*Enter th
trafficLight(signal1)
(ii) define _traffictight (signal);
Colors=(*RED", "YELLOW", “GREEN")
if (signal not in colors)
© colour of the traffic light:
)
Print("Please enter a valid Traff
signall = input("Enter the
trafficlight(signal1)
(iii) det traftictight(signal)
colors=("RED", "YELLOW" "GREEN")
if (signal not in colors):
Print("Please enter a valid Traffic Light colour in CAPITALS")
trafficlight (signal1)
(iv) def trafficLight (signal)
colors=("RED", "YELLOW", "GREEN")
if (signal not in colors)
print("Please enter a valid Traffic Light colour in CAPITALS")
signal1 = input("Enter the colour of the traffic light: ")
trafficlight(signal1)
(6) Further Ramesh told him to write a user defined function light) that aecepts a string as input
and returns 0 when the input is RED.Also print the return vahie %49
Which of the following code definition is correct in this e6nitéxe#!! 1 900 (04)
(D def Light(colouz): aneM sleomnesl 0 ogbalword off tot oT (ls)
if (colour = _ ne
return(0); ’
‘ic Light colour in CAPITALS")
colour of the traffic light: ")
print (light (colour) )
(ii) def Light (colour):
- if (colour == "RFD")
print (return(0)
S}—-gnoiizaul sqyf svloo(t0 bn see ysComputeeSéienoe.withRython — BB.
bi :said Ramesh to write a user defined function light() that accepts
ind returns 0 when the input is RED,1 when the input is YELLOW and 2 when
1. The input should be passed as an argument.
Ramesh has written the following codes, which of them is correct.
( def light(colour):
: if (colour == "RED"):
5 return(0);
elif (colour == "YELLOW"
return (1)
else:
return(2)
(ii) define Light (colour):
4f (colour =- "RED"):
return(0)
elif (colour == “YELLOW"):
return (1)
else:
return(2)
(iii) def Light(colour):
if (colour = “RED"):
return(0);
elif (colour = "YELLOW"):
return (1)
else:
return(2)
(iv) None of the above
(@) To test the knowledge of Ramesh,Manject has written the following code
nun = 5
def myfunci():
fnum=int (input (“enter number”))
print(“Accessing num =", num)
num = 10
Print(“num reassigned =",num)
myfunc1()He asked which of the folk te
function. SV o™iNG fiction in the given program isnot standard library
CR) @ inpuy
: i ‘
7, Sinan is a programmer, she has writen the ee i) myfunel() iv), print()
different shapes of leather bags Wing Program to calculate the cost of designing
sProgran to calculate the cost o
function definition different types of Leather bags.
defcyl(h,r)
area_cyl = 2*3.16*r+h y
return(area_cyl) tea of cylindrical pare
sfunction definition
def con(1,r):
area_con = 3.14*r*] #area
return(area_con)
#function definition
deftaxprice(cost): scompute payable anount for the bag
tax = 0.48 * cost;
net_price = cost + tax
return(net_price)
Of conical part
Line 1
Line 2
print("Enter values of cylindrical
h = float(input(*Height: °))
r = float(input("Radius: *))
esa_cyl = cyl(h,r) #function call
1 = float(input("Enter slant height of the
¢sa_con = con(1,r) #Line 3
scalculate the area of the canvas used for making the bag
canvas_area = csa_cyl + csa_con
print ("Area of canvas = ",canvas_area,” m2
Calculate the cost of canvas
part of the bag in meter:
‘onical bag in meters:
unit_price = float(input("Enter cost of 1 m2 canvas in Tupees: "))
total_cost = unit_price * canvas_area
print ("Total cost of canvas before tax = *,total_cost)
print ("Net anount payable (including tax) = *,tax_price(total_cost))
(@) Simran’s friend, Madan saw the code and he is bit confused on the use of return statement
in function definition. To make him understand Simran said the following statements about
return statement.
1. It shows the end of the execution of a fun
II. returns control to the calling function,
III. A return statement can return a value to the cal
jing function.
IV. python function will always have a return value
Tell him which of the above statement is true.
(® Lonly (i) Land II only
(iii) and Il (iv) All the four statements are true
Computer Science with Python = 83.(8) The default return value for a function in MR a oe (h) Nowe
@ integer (i) float Uy Come r
(©) What is the return datatype of the function tax_price() in #Line nee
() integer (ii) float (iii) ere are both integer types?
(@_ What is the return data type of the function con(1,r) ,if | and r 8 vd
is iif) Complex
( integer (ii) float (iii
(©) Madan changed the code in Line number 3 to as shown below:
csa_con = con(110,r) Line 3
in the function ? :
Ne eee es (ii) function result will be affected
i) no chang
i d
(iii) Syntax error will be displayed (iv) None of the mentione
8. Sneha has written a program to calculate area of different shapes for her assignment,
® Program to calculate area of different shapes
# This function calculates area of circle
inport math
detc_area(x):
returnpi*x*x
# This function calculates area of rectan.
defrect_area(x, y):
return x * y
# This function area of square
defsq_area(x):
return x * x
# This function area of triangle
deftr_area(x, y):
return0.5*(x+y)
Print("Select operation.")
print("1.circle")
print ("2. rectangle")
print("3. square")
print("4. triangle")
while True:
# Take input from the user
choice = input("Enter choice(1/2/3/4): “)
# Check if choice is one of the four options
if choice in ('1', + ae
if choice
84 Pagether wwith® Competency Based and Objective Type Questions —12elif choice == °3":
uml = float(input(*Enter side : -))
print(sq_area(numi, num2))
elif choice == ‘4*:
nul = float(input("Enter base
nun2 = float(input("Enter height :
print(tr_area(numi, nun2))
break
else:
print(*Invalid Input")
(a) Mohini, Sneha's friend did not undetstand the concept of function. She asked:
What are the possible combinations of functions?
@1 (2 (wi) 3 4
(6) Which of the following statement is true about functions.
|. Functions returning some value are called non-void functions
Il. Function not returning any value are called void functions.
al i
This function is an example of void function with a return statement
(@ only I true
(i only | and Ul are tue
(iii) statement 1, Il and III are correct
(i) All the four statements are correct
(©) Further, Mohini changed the function call in the statement,
area(num|=10,num2)
Will the program run?
© yes
(Emr willbe occured4@ Agen, she changed the function call statement 17_a7ea/num1=19, ny,
eee = 10,num2=23)
Will the program run?
©) yes
(iii) can’t say
(e) Which of the following arguments, is suppo!
(i) positional arguments
(iii) keyword arguments
9. Manisha has written following code:
(ii) Error will be occurred
(iv) None of the above
ried by python as formal argu
(ii) default arguments
(iv) all of the above
a-8
def demo(x, y, z):
as3
print("%d" ta) line 1
a + (x+y)
Zz =
eye x
print("td %d %d" wa, z, y)) sline 2
a-2
bz5
deno(a, a, b)
print (md %d 2d" %(a, a, b)) —sline 3
(a) What will be the output in #Line 1?
@3 (i) 5 (iii) 8 (iv) None of the aby
(6) What will be the output in #Line 2?
@794 (W279 (ii) 3-7 9 (225
(c) What will be the output in #Line 3?
@794 27.9 (i) 379 2g Za
(@) In the program, in which declaration a global variable is declared?
@ 3 (i) a8
(iif) a2 (iv) None of the mentioned
(e) In the program, in which declaration a local variable is declared
@ 3 (i) a8
(iii) a2 (iv) None of the mentioned
10. Mandar is learning python. To test his understanding in Python his friend asked him a #4
questions. He wrote the following code
num = 9
def add9()
fun = nun + 9
print (num)
2d49()
BE Fagecher cocek® Competency Based and Objective Type Questions —12(ii) global variable
(iii) Arguments (i) positional parameters
(a) Again he changed the code as written below:
runs 26
2609(num)
‘Now he asked about the output of the above program.
wos (@) 33
(ii) 19 (iv) None of the mentioned
(e) Further he changed the code as written below:
nm 9
def ada9(nun
rum = nun + 9
print
une24
add9(num)
Now again he asked about the output of the above program.
os w 33
(ii) 19 (iv) None of the mentioned
Computer Science with Python 87CHAPTER 2: Functions
Multiple Choice Questions
1, @ 2 ©) 3. (@) 4. () 5. (0)
6. (b) 7. (© 8. (c) 9. (0) 10. (a)
11. (a) 12. (a) 13. (©) 14. (a) 15. (c)
16. (b) 17. (a) 18. (b) 19. (d) 20. 60
21. (a) 22. (c) 23. (a) 24. (a) 25. (a)
26. (a) 27. (c) 28. (d) 29. (a) 30. (6)
31. (b) 32. (a) 33. (d) - 34. (6) 35. (0)
36. (a) 37. (c) 38. (c) 39. 40. (0)
41. (d) 42. (d) 43. (0) 44. (b) 45. (d)
46. (b) 47. () 48. (a) 49. (a) 50. (6)
Computer Science with Python 1155. @ 53. (b) 54. (d)
51. (c) 58. (d) 59. {0
56. (a) ‘s i ae 64. (6)
61. (6) Gh (a) 68. (iv) 69. (c)
66. (6) ee Oy ah) 14. (0)
11. (0) 7s O) et) 79. (a)
. s 82. (b) 83. (4) 84. (b)
86. (b) 87. (0) 88. (c)
Assertion-Reasoning Type MCQs 4
89. (a) 90. (c) 91. (6) 92. (c) 93. (a)
) 94. (a) 95. (a) 96. (b) 97. (a) 98. (6)
Case-Based MCQs
1. (a) (ii) (b) (iv) (c) (iii) (d) (ii) © ty
2. (a) (ii) (b) (iv) (c) (iii) (d) (iv) © @
3. (a) (ii) (8) (iii) (©) (i) (@) (i) 06
4. (a) (») (0) () (c) (ii) (d) (ii) (e) (iii)
5. (a) (iv) (b) (ii) () (i) (yeu ©
6. (a) (iv) (6) () (c) (i) (d
7. (a) (iv) (b) (iv) (c) (ii) d aa
8. (a) (iv) (b) (iv) (c) (ii) (ad (i) (a
9. (a) (b) @ (c) (iv) 1) (ii) () @
_
=
ONY 5) (Cc): @) 1) (iii) (e) (i)