Previous Index Next

Review Questions

1. Which of the following is correct way to define a function header?
a. def function_name():
b. define funcion_name():
c. function function_name():
d. return function_name():


2. Which of the following is the correct way to call a function?
a. def my_func()
b. my_func()
c. return my_func
d. call my_func()


3. Which of the following function header is correct?
a. def cal_si(p=100, r, t=2):
b. def cal_si(p=100, r=8, t):
c. def cal_si(p, r=8, t):
d. def cal_si(p, r=8, t=2):


4. What will the following code display?

def add (num1, num2):
    sum = num1 + num2

sum = add(20,30)
print(sum)


5. What will the following code display?

def my_func(var1=100, var2=200):
    var1 += 10
    var2 = var2 - 10
    return var1+var2

print(my_func(50),my_func())


6. What will the following code display?

def ChangeVal(M,N):
    for i in range(N):
        if M[i]%5 == 0:
            M[i]//=5
        if M[i]%3 == 0:
            M[i]//=3

L = [25,8,75,12]
ChangeVal(L,4)
for i in L:
    print(i,end="#")


7. What will the following code display?

def foo(u, v, w=3):
        return u * v * w
 
def bar(x):
    y = 4
    return foo(x, y)

print(foo(4,5,6))
print(bar(10))


8. What will the following code display?

def change(t1,t2):
    t1 = [100,200,300]
    t2[0]= 8

list1 = [10,20,30]
list2 = [1,2,3]
change(list1, list2)
print(list1)
print(list2)


9. What will the following code display?

def dot(a, b):
    total = 0
    for i in range(len(a)):
        total += a[i] * b[i]
    print(total)

x = [10,20,30]
y = [1,2,3,4]
dot(x,y)


10. What will the following code display?

def change(num1 ,num2=50):		
    num1 = num1 + num2		
    num2 = num1 - num2		
    print(num1, '#', num2)				

n1 = 150			
n2 = 100			
change(n1,n2)		
change(n2)
change(num2=n1,num1=n2)


11. Write the output of following code.

a = 7

def printA():
    print('Value of a is', a)

def foo(value):
    global a
    a = value
    print('Inside foo, a is',a)

def bar(value):
    a = value
    print('Inside bar, a is',a)

bar(10)
printA()
foo(20)
printA()

12. What will the following code display?

x = 3
def myfunc():
    global x
    x+=2
    print(x, end=' ')

print(x, end=' ')
myfunc()
print(x, end=' ')


13. What will the following code display?

value = 50
def display(N):
    global value
    value = 25
    if N%7==0:
        value = value + N
    else:
        value = value - N

print(value, end="#")
display(20)
print(value)


Programming Exercises

For Lab Programming Questions click here.

Previous Index Next