AmbifulWorksheets
Practice that never repeats
CBSE · Class 12 · Computer Science

Functions

Standard difficulty · 20 questions · 40 marks · Time: 43 minutes

Name: Date: Score: ____ / 40

Show your working for Sections B and C. Answers are on the last page — try every question first!

Section A — Choose the correct answer8 × 1 = 8 marks
1.
The values written in a function call are called:
  1. return values
  2. local variables
  3. parameters
  4. arguments
2.
What does this print?
def area(l, b=5):
    return l * b + 9

print(area(8), area(8, 9))
  1. 49 54
  2. 17 81
  3. 50 81
  4. 49 81
3.
What does this print?
def total(p, q=2, r=5):
    return p + q * r

print(total(1, 9))
  1. 46
  2. 15
  3. 11
  4. 64
4.
What does this print?
x = 13
def change():
    global x
    x = x + 8

change()
change()
print(x)
  1. 37
  2. 13
  3. 29
  4. 21
5.
What does this print?
x = 11
def show():
    x = 45
    return x * 3

print(show(), x)
  1. 135 11
  2. 33 11
  3. 33 45
  4. 135 45
6.
What does this print?
def calc(a, b):
    return a + b, a * b

s, p = calc(3, 8)
print(p, s)
  1. 24 11
  2. 24 24
  3. (24, 11)
  4. 25 11
7.
Which call of this function gives an error?
def show(name, age, city='Delhi'):
    print(name, age, city)
  1. show(age=16, name='Zoya')
  2. show('Zoya', 16)
  3. show(city='Pune')
  4. show('Zoya', city='Agra', age=16)
8.
What does this print?
import math
print(math.pow(6, 3), 6 ** 3)
  1. 217.0 216
  2. 215.0 216
  3. 216.0 216
  4. 18.0 18
Section B — Short answer8 × 2 = 16 marks
9.
What is the difference between a parameter and an argument?
10.
What does this print? Give (a) the first value (b) the second.
def area(l, b=9):
    return l * b + 9

print(area(6), area(6, 8))
11.
What does this print?
def total(p, q=4, r=5):
    return p + q * r

print(total(7, r=5))
12.
What does this print?
x = 10
def change():
    global x
    x = x * 2

change()
change()
change()
print(x)
13.
What does this print?
def update(L, n):
    for i in range(len(L)):
        if L[i] % 2 == 0:
            L[i] = L[i] + 5
    n = n + 5

nums = [27, 18, 17, 13]
m = 10
update(nums, m)
print(nums, m)
14.
Write the letters this program prints, in order, separated by commas.
def one():
    print('S')

def two():
    print('T')
    one()

two()
two()
two()
two()
15.
What does this program print? Give (a) the first line (b) the second.
def double(n):
    print(n * 5)

r = double(12)
print(r)
16.
What does this print?
def power(x, n=4):
    return x ** n

print(power(3) + power(9, 1))
Section C — Word problems4 × 4 = 16 marks
17.
Explain with an example how default and keyword arguments work, and the rules for using them.
18.
Write the output of each program and explain the difference.
(a)
def update(L, n):
    for i in range(len(L)):
        if L[i] % 2 == 0:
            L[i] = L[i] + 9
    n = n + 9

nums = [24, 27, 18, 10]
m = 7
update(nums, m)
print(nums, m)
(b)
x = 15
def show():
    x = 57
    return x * 5

print(show(), x)
19.
Trace this program. Give (a) the first line it prints (b) the second (c) the third.
def stats(L, limit=21):
    big = []
    for x in L:
        if x > limit:
            big.append(x)
    return len(big), sum(big)

n, s = stats([9, 46, 22, 36, 28, 11])
print(n)
print(s)
print(stats([9, 46, 22, 36, 28, 11], 31))
20.
(a) What does this program print? (b) How many times is add() called? (c) Why is the word global needed inside add()?
count = 0

def add(x):
    global count
    count = count + 1
    return x

total = 0
x = 2
for i in range(6):
    total = total + add(x)
    x = x + 3
print(total, count)
AmbifulWorksheets
Practice that never repeats
CBSE · Class 12 · Computer Science

Answer key

Functions · AW-12CS-FNC-2026-V1 · For parents — fold back or tear off before handing the sheet to your child.

QAnswerWorking
1(d) arguments—
2(d) 49 81b takes its default value only when it is not passed
3(a) 46match keyword arguments by name, the rest by position; missing ones take their defaults
4(c) 29global x makes the function change the variable outside it
5(a) 135 11the x inside show() is a new local variable; the global x is unchanged
6(a) 24 11return a + b, a * b returns a tuple of two values
7(c) show(city='Pune')name and age are missing
8(c) 216.0 216math.pow() always returns a float; ** on two ints gives an int
9A parameter is the name in the function header; an argument is the value passed in the function call.—
10(a) 63; (b) 57b takes its default value only when it is not passed
1127match keyword arguments by name, the rest by position; missing ones take their defaults
1280global x makes the function change the variable outside it
13[27, 23, 17, 13] 10the list is the same object inside the function, so changes to it stay; n is a new local name
14T, S, T, S, T, S, T, Sa def only defines a function; it runs when called, and two() calls one()
15(a) 60; (b) Nonedouble() prints but returns nothing, so r is None
16903 ** 4 = 81, then + 9
17def f(a, b=2, c=3): return a + b * c. f(1) = 7, f(1, 4) = 13, f(1, c=5) = 11, f(c=5, a=1) = 11. Default parameters must come after the others in the header; in a call, keyword arguments come after positional ones and no parameter may get two values.—
18(a) [33, 27, 27, 19] 7; (b) 285 15. A list passed to a function is the same object, so changing its items is seen outside; assigning to a name inside a function makes a new local variable.mutable list changed in place; local names hide global ones
19(a) 4; (b) 132; (c) (2, 82)above 21: 46, 22, 36, 28; above 31: 46, 36
20(a) 57 6; (b) 6; (c) without it, count = count + 1 makes count local and reading it first gives an UnboundLocalError.x takes 2, 5, 8, 11, 14, 17