A
A
Q uestion1 :
( c) x= 3 ( d) x= 3
wh ile( x> 3 ) wh ile( x> 3 ) :
{} pass
Page 1 of 13
4. W h atisth e indexnumberofth e l
astel
em entofatupl
e with 5 0 el
em ents?
( a) 5 0 ( b) 4 9 ( c) -1 ( d) band c
5. T h e l
astprinted expressionisassigned to th e . . . . . . . . . . . . . . . variabl
e
( a) l
ast ( b) _ ( c) var ( d) exp
A= 2 5
print( a)
( a) error ( b) 2 5 ( c) a ( d) A
8. a= input( “ enteryourinput: ”)
print( type( a) )
( a) int ( b) string ( b) fl
oat ( d) bool
( a) 4 0 ( b) x ( b) 2 1 ( d) 2 4 1 6
Page 2 of 13
Q uestion2 :
C h oose th e equival
entcode for each ofth e fol
lowing:
x= 3
ifx> 3 :
print( ‘x> 3 ’ )
11. elifx< 3 :
print( ‘x< 3 ’ )
else:
print( ‘x= 3 ’ )
( a) x= 3
ifx> 3 print( ‘x> 3 ’ ) el
ifx< 3 print( ‘x< 3 ’ ) el
se print( ‘x= 3 ’ )
x= 3
( b)
ifx> 3 print( ‘x> 3 ’ ) el
se ifx< 3 print( ‘x< 3 ’ ) print( ‘x= 3 ’ ) el
se
( c) x= 3
print( ‘x> 3 ’ ) ifx> 3 el
se print( ‘x< 3 ’ ) ifx< 3 el
se print( ‘x= 3 ’ )
x= 3
( d) print( ‘x> 3 ’ ) ifx> 3 ifx< 3 print( ‘x< 3 ’ ) print( ‘x= 3 ’ ) el
se
Page 3 of 13
13.
num= 3 5
ifnum% 2 = = 0 :
print( 'even')
else:
print( 'odd')
num = 3 5
( a)
print( [num % 2 = = 0 ]( 'odd', 'even') )
num = 3 5
( b) print( [num % 2 = = 0 ]( 'even', 'odd') )
num = 3 5
( c) print( ( 'even', 'odd') [num % 2 = = 0 ])
num = 3 5
( d)
print( ( 'odd', 'even') [num % 2 = = 0 ])
alph a= ( 'a', 'b', 'c', 'd') alph a= ( 'a', 'b', 'c', 'd')
( a) ( b) for i inrange( l en( al ph a) ) :
for i inrange( l en( al ph a) ) :
print( i) print( al ph a)
alph a= ( 'a', 'b', 'c', 'd') alph a= ( 'a', 'b', 'c', 'd')
( c) for i inal ph a: ( d) for i inrange( l en( al ph a) ) :
print( i) pass
Page 4 of 13
15. x= 3
z = []
for i inrange( 3 ) :
z [i: ]= [i]
x= 3
( a) z = [i for i inrange( 3 ) ]
x= 3
( b)
z = [i ]
x= 3
( c)
z = for i inrange( 3 ) [i ]
( d) x= 3
z = [for i inrange( 3 ) i]
z = []
16.
z [0 : ]= 3
z = [] z = []
( a) ( b)
z [0 ]= 3 z+ = ( 3 )
z = [] z = []
( c) z . append( 3 ) ( d) z [- 1 ]= 3
Page 5 of 13
Q uestion3 :
C h oose th e error l
ine num ber ineach ofth e fol
lowing:
1. x= 1 2
17. 2. y= 4
3. fun( x, y)
4. deffun( x, y) :
5. print( x, y)
( a) l
ine 1 ( b) l
ine 2 ( c) l
ine 5 ( d) l
ine 3
18.
1. defcalcul
ate( a, b, c= [], d) :
2. returna+ b- d
3. w= x= 3
4. y, z = 5 , [1 , 2 ]
5. print( cal cul ate( x, y, z , w)
( a) l
ine 1 ( b) l
ine 2 ( c) l
ine 3 ( d) l
ine 4
1 . defsquare( * * nums, x) :
19. 2 . sqnums= { }
3 . for num, valinnums. items( ) :
4 . sqnums[num]= val * * 2
5 . return sqnums
6 . x= square( q= 2 , f= 4 )
7 . print( x)
( a) l
ine 1 ( b) l
ine 2 ( c) l
ine 3 ( d) l
ine 4
Page 6 of 13
1. deffoo( a, b) :
20. 2. c= a+ b
3. returnc
4. x= 3
5. print( foo( x) )
( a) l
ine 2 ( b) l
ine 3 ( c) l
ine 4 ( d) l
ine 5
1. deffun( * arg) :
21. 2. x= l
en( arg)
3. fori inrange( x) :
4. print( arg[i])
5. fun( 2 , 3 , 4 , a= 5 )
( a) l
ine 2 ( b) l
ine 3 ( c) l
ine 4 ( d) l
ine 5
1. s= { 1 , 2 , 3 }
22.
2. s. add( 3 )
3. print( s[0 ])
4. print( 9 ins)
( a) l
ine 1 ( b) l
ine 2 ( c) l
ine 3 ( d) l
ine 4
( a) l
ine 1 ( b) l
ine 2 ( c) l
ine 3 ( d) l
ine 4
Page 7 of 13
1. defexp( * nums, x) :
24. 2. fori innums:
3. print( i)
4. exp( 1 , 4 , 5 , 7 )
( a) l
ine 1 ( b) l
ine 2 ( c) l
ine 3 ( d) l
ine 4
25. 1 . x= 5
2 . ifx> 0 :
3 . print( ‘positive’ )
4 . el se:
5 . print( ‘negative’ )
( a) l
ine 1 ( b) l
ine 2 ( c) l
ine 3 ( d) l
ine 4
1. x= { }
26. 2. x. add( 2 )
3. y= x
4. print( x)
( a) l
ine 1 ( b) l
ine 2 ( c) l
ine 3 ( d) l
ine 4
Page 8 of 13
Q uestion4 :
C h oose th e th e correctoutputeach ofth e fol
lowing:
defmyfun( a, b, c= [1 , 2 , 3 ]) :
c. append( a)
c. append( b)
27.
returnc
x, y= 4 , 8
print( myfun( b= x, a= y) )
( a) [1 , 2 , 3 , 8 , 4 ] ( b) no output ( c) [1 , 2 , 3 ] ( d) error
if- 5 0 inrange( - 1 , - 1 0 0 ) :
28. print( 'Y es')
else:
print( 'N o')
( a) Y es ( b) N o ( c) error ( d) output
deffoo( * grades) :
29. print( len( grades) )
print( type( grades) )
foo( 9 6 , 8 2 , 7 0 )
( a) 3 tupl
e ( b) 6 ( c) 3 Dictionary ( d) 6 tupl
e
Page 9 of 13
x= l
am bdaa: a* * 2
30. print( x( 3 ) )
( a) 6 ( b) 3 ( c) 9 ( d) 5
31.
t1 = ( 9 , 5 , 0 )
t2 = 'w', 'n', 'f'
print( t1 + t2 )
( a) 9 5 0 w n f ( b) t1 + t2 ( c) 9 5 0 ( d) w n f
32. x= 5
y= 8
txt= “ th e val
ue of{ 2 } + { 1 } is{ 0 }”. format( x+ y, y, x)
print( txt)
( a) th e val
ue of{ 2 } + { 1 } is{ 0 } ( b) th e val
ue ofx+ y isx+ y
( c) th e val
ue of5 + 8 is1 3 ( d) th e val
ue of1 3 + 8 is5
33. x= [0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 ]
print( x[1 : 6 : 2 ])
( a) 1 3 5 ( b) 0 1 2 3 4 ( c) 1 2 3 4 ( d) 0 2 4
34. z= { 6 , 9 , 3 }
z . remove ( 'b')
print( z )
Page 10 of 13
35. defsquare( sqr, nums) :
forn, valinnums. items( ) :
sqr[n]= val * * 2
h= {}
x= { 'a': 2 , 'b': 1 }
square( h , x)
print( h )
36. h = [3 , 2 , 1 ]
m = h [: ]
ifid( h ) = = id( m) : print( " yes" )
else: print( " N o" )
deffoo( x) :
fori inrange ( 2 ) :
37. x. append( i)
x= []
foo( x)
print( x)
( a) [] ( b) [0 , 1 ] ( c) x ( d) no output
defsum ( n) :
38. ifn= = 1 : return1
returnn+ sum( n- 1 )
print( sum( 3 ) )
( a) 4 ( b) 1 0 ( c) 6 ( d) [5 3 9 ]
Page 11 of 13
39. x= 5
wh il e( x< 9 ) :
x+ = 1
ifx> 5 : break
else: print( x)
( a) error ( b) no output ( c) 6 ( d) 8
deffun( s) :
s. append( 'worl
d')
40. e= ['h el l
o']
fun( e)
print( e)
( a) e ( b) ['h el
lo'] ( c) ['h el
lo', 'worl
d'] ( d) ['worl
d']
Page 12 of 13
rem ove( ) remove anitem from aset. Ifth e item to remove
doesnotexist, remove( ) wil
lraise anerror.
set( ) createsaset.
item s( ) returnsal
istofdictionary’ s( key, val
ue) tupl
e pairs.
l
en( x) returnsth e numberofitemsinth e col
lectionx.
Page 13 of 13