0% found this document useful (0 votes)
20 views2 pages

Working With Functions - Set 1 - QP

Computer science study material
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views2 pages

Working With Functions - Set 1 - QP

Computer science study material
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Working with Functions - Set 1 print(message * times)

say('Hello')
1.Which of the following is the use of say('World', 5)
function in python?
a) Functions are reusable pieces of programs
b) Functions don’t provide better modularity 8.What is the output of the below program?
for your application def func(a, b=5, c=10):
c) you can’t also create your own functions print('a is', a, 'and b is', b, 'and c is', c)
d) All of the mentioned func(3, 7)
func(25, c = 24)
func(c = 50, a = 100)
2.Which keyword is use for function?
a) fun
b) define 9.What is the output of below program?
c) def def maximum(x, y):
d) function if x > y:
return x
elif x == y:
3.What is the output of the below program? return 'The numbers are equal'
def printMax(a, b): else:
if a > b: return y
print(a, ‘is maximum’) print(maximum(2, 3))
elif a == b:
print(a, ‘is equal to’, b)
else: 10.Which are the advantages of functions in
print(b, ‘is maximum’) python?
printMax(3, 4) a) Reducing duplication of code
b) Decomposing complex problems into
simpler pieces
4.What is the output of the below program? c) Improving the clarity of the code
def sayHello(): d) All of the mentioned
print('Hello World!')
sayHello()
sayHello() 11.What are the two main types of
functions?
a) Custom function & User defined function
5.What is the output of the below program ? b) Built-in function & User defined function
x = 50 c) User defined function & System function
def func(x): d) System function & Built-in functions
#print(‘x is’, x)
x=2
#print(‘Changed local x to’, x) 12.Which of the following is the use of id()
func(x) function in python?
print(‘x is now’, x) a) Id returns the identity of the object
b) Every object doesn’t have a unique id
c) All of the mentioned
6.What is the output of the below program? d) None of the mentioned
x = 50
def func():
global x 13.Which of the following refers to
print('x is', x) mathematical function?
x=2 a) sqrt
print('Changed global x to', x) b) rhombus
func() c) add
print('Value of x is', x) d) fact

7.What is the output of below program?


def say(message, times = 1):
14.What is the output of below program? 21.What is the output of the following piece
def cube(x): of code?
return x * x * x def a(b):
x = cube(3) b.append(5)
print( x) c = [1, 2, 3, 4]
a(c)
print(len(c))
15.What is the output of the below program?
def C2F(c):
return c * 9/5 + 32 22.What is the output of the following code?
print (C2F(100)) a=10
print (C2F(0)) b=20
def change():
global b
16.What is the output of the below program? a=45
def power(x, y=2): b=56
r=1 change()
for i in range(y): print(a)
r=r*x print(b)
return r
print (power(3))
print (power(3, 3)) 23.What is the output of the following code?
def change(i = 1, j = 2):
i=i+j
17.What is the output of the below program? j=j+1
def sum(*args): print(i, j)
'''Function returns the sum change(j = 1, i = 2)
of all values'''
r=0
for i in args: 24.What is the output of the following code?
r += i def change(one, *two):
return r print(type(two))
print (sum(1, 2, 3)) change(1,2,3,4)
print (sum(1, 2, 3, 4, 5)) a)<class ‘Integer’>
b)<class ‘tuple’>
c)<class ‘Dictionary’>
18.What is a variable defined outside a
function referred to as?
a)A static variable 25.What is the output of the following code?
b)A global variable def display(b, n):
c)A local variable while n > 0:
d)An automatic variable print(b,end="")
n=n-1
display('z',3)
19.What is a variable defined inside a
function referred to as?
a)A global variable
b)A volatile variable
c)A local variable
d)An automatic variable

20.What is the output of the following code?


i=0
def change(i):
i=i+1
return i
change(1)
print(i)

You might also like