Class 12 Questions : Function Set 2

21.
What is the output of the code shown?

def f():
    global a
    print(a)
    a = "hello"
    print(a) 
a = "world" 
f()
print(a)

a) hello
hello
world
b) world
hello
hello
c) hello
world
world
d) world
hello
world

22.
What is the output of the code shown below?

def f1(a,b=[]):
    b.append(a)
    return b
print(f1(2,[3,4]))

a) [3,2,4]
b) [2,3,4]
c) Error
d) [3,4,2]

23.
What is the output of the code shown below?

def f(p, q, r):
    global s
    p = 10
    q = 20
    r = 30
    s = 40
    print(p,q,r,s)
p,q,r,s = 1,2,3,4
f(5,10,15)

a) 1 2 3 4
b) 5 10 15 4
c) 10 20 30 40
d) 5 10 15 40

24.
What is the output of the code shown below?

def f(x):
    print("outer")
    def f1(a):
        print("inner")
        print(a,x)
f(3)
f1(1)

a) outer and error
b) inner and error
c) outer and inner
d) error

25.
The output of code shown below is:

x = 5 
def f1():
    global x
    x = 4
def f2(a,b):
    global x
    return a+b+x
f1()
total = f2(1,2)
print(total)

a) Error
b) 7
c) 8
d) 15