Review of XI
User Defined Functions
Lists and Dictionaries
Library Functions
Scope
100
c=9+4j

Write a statement to print the imaginary component of c

print(c.imag)

100

Dictionaries are indexed by ____________ and lists are indexed by _____________ 

keys

integers

100

The function fabs() belongs to which module:

math

100

Namespace resolution in Python is done by _____________ order

LEGB

200

Name the augmented operator of Python

+=

-=

*=

200


What is the output of the following code?

 i=5
def change(i):

     i=i+1

     return i

for i in (1,2,3)

     change(i)
     print(i)


 1

2

3

200

>>> a = ['foo', 'bar', 'baz', 'qux', 'quux', 'corge']

>>>max(a[2:4])

qux

200

…………..function returns the smallest integer greater than the given floating point number.

ceil()

200

d={}

def f(i):

    d[i]=i

for i in range(4):

    f(i)

print(d)

{0: 0, 1: 1, 2: 2, 3: 3}

300

Rahul has created the a tuple containing some numbers as 

>>>t=(10,20,30,40) 

He wants to add an element 60 to it 

How does he do it

t=t+(60,)
300


def change(i = 1, j = 2):

          i=i+j 

          j=j+1 

          print(i, j)

change(j = 1, i = 2)


3 2

300

d={4:2,9:3}

d2=d.copy()

print(d is d2)

False

300

What will be the output of the following Python function? all([2,4,0,6])

False

300

def f1():

    global x 

    x+=x

    print(x)

x=12

f1()

print("x")

24

x

400

import random

a=[4,1,9,6]

print(a.shuffle())

None

400

def foo(x):

    x = ['def', 'abc']

    return id(x)

q = ['abc', 'def']

print(id(q) == foo(q))

False

400

x = [10, [3.141, 20, [30, 'baz', 2.718]], 'foo']

Write a statement to print zb from x

print(x[1][2][1][::-2])

400

Write a statement to generate a random number between 15.5 and 40.5

random.uniform(15.5,40.5)

400

#What is the output of the code shown? 

#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)

7

500

Find the output

a=input('Enter a number')

for i in range(1,4):

    a=a*i

print(a)

#Input entered is 12.2

12.212.212.212.212.212.2

500

Find the output

def foo(i, x=[]):

    x.append(x.append(i))

    return x

for i in range(3):

    y = foo(i) 

print(y)

[0, None, 1, None, 2, None]

500

D = {1 : {'A' : {1 : "A"}, 2 : "B"}, 3 :"C", 'B' : "D", "D": 'E'} 

print(D[D[D[1][2]]]) 

E

500

print(len(str(round(4.673))))

1

500

x = 10

print('x is ',x)

def outer():

    x = 20

    print('x is ',x)

    def inner():

        x = 30

        print('x is ',x)

        print(len(str(x))

    inner()

outer()

Name the variables showing 

local scope

enclosed scope

built in scope 

Local 

x=30

Enclosed 

x=20

Global

x=10

Built in 

len(str(x))