Académique Documents
Professionnel Documents
Culture Documents
IT Workshop: Test 1
1. What is the output of the following? 6. What is the output of the following?
a) [„h‟, „e‟, „l‟, „l‟, „o‟]. 10. Which of the following is not the correct syntax for
b) [„hello‟]. creating a set?
c) [„llo‟].
d) [„olleh‟]. a) set([[1,2],[3,4]])
b) set([1,2,2,3,4])
5. What is the output of the following? c) set((1,2,3,4))
d) {1,2,3,4}
x = [i**+1 for i in range(3)];
print(x);
a) [0, 1, 2].
b) [1, 2, 5].
c) error, **+ is not a valid operator
d) error, „;‟ is not allowed
1|Page
Indian Institute of Information Technology, Nagpur.
IT Workshop: Test 1
11. Which of the following statements create a 15. What is the output of the following?
dictionary?
x = 2
a) d = {} for i in range(x):
b) d = {“john”:40, “peter”:45} x -= 2
c) d = {40:”john”, 45:”peter”} print (x)
d) All of the mentioned
a) 0 1 2 3 4 …
12. Read the code shown below carefully and pick out b) 0 -2
the keys? c) 0
d) error
d = {"john":40, "peter":45}
16. What is the output of the following code?
a) “john”, 40, 45, and “peter”
b) “john” and “peter” places = ['Bangalore', 'Mumbai',
c) 40 and 45 'Delhi']
d) d = (40:”john”, 45:”peter”) places1 = places
places2 = places[:]
13. What Will Be The Output Of The Following Code
places1[1]="Pune"
Snippet?
places2[2]="Hyderabad"
print(places)
a=[1,2,3,4,5,6,7,8,9]
a[::2]=10,20,30,40,50,60 a) [„Bangalore‟, „Pune‟, „Hyderabad‟].
print(a) b) [„Bangalore‟, „Pune‟, „Delhi‟].
c) [„Bangalore‟, „Mumbai‟, „Delhi‟].
a) ValueError: attempt to assign sequence of size 6 to d) [„Bangalore‟, „Mumbai‟, „Hyderabad‟].
extended slice of size 5
b) [10, 2, 20, 4, 30, 6, 40, 8, 50, 60]
c) [1, 2, 10, 20, 30, 40, 50, 60] 17. What is the output of the following code?
d) [1, 10, 3, 20, 5, 30, 7, 40, 9, 50, 60]
a=165
14. What is the output of the following? b=sum(list(map(int,str(a))))
print(b)
x = ['ab', 'cd']
for i in x: a) 561
x.append(i.upper()) b) 5
print(x) c) 12
d) Syntax error
a) [„AB‟, „CD‟].
b) [„ab‟, „cd‟, „AB‟, „CD‟]. 18. What is the output of the following code?
c) [„ab‟, „cd‟].
d) none of the mentioned a=[13,56,17]
a.append([87])
a.extend([45,67])
print(a)
2|Page
Indian Institute of Information Technology, Nagpur.
IT Workshop: Test 1
s=set([1, 2, 3]) a) 1
print(s.union([4, 5])) b) 2
print(s|([4, 5])) c) 4
d) Error, the keys can‟t be a mixture of letters and
numbers.
3|Page
Indian Institute of Information Technology, Nagpur.
IT Workshop: Test 1
26. What is the output of the following snippet of code? 30. What is the output of the following?
IT Workshop: Test 1
a) Error, tuples are immutable 39. Which of the following matrices will throw an error
b) ((„check‟,),) in Python?
(((„check‟,),),).
c) ((„check‟,)‟check‟,) a) A = [[1, 2, 3],
d) ((„check‟,)‟check‟,) [4, 5, 6],
(((„check‟,)‟check‟,)‟check‟,) [7, 8, 9]]
36. What is the output of the line of code shown below? b) B = [[3, 3, 3]
[4, 4, 4]
s1= {1, 2, 3} [5, 5, 5]]
s1.issubset(s1)
c) C = [(1, 2, 4),
a) True (5, 6, 7),
b) Error (8, 9, 10)]
c) No output
d) False d) D = [2, 3, 4,
3, 3, 3,
37. What is the output of this code? 4, 5, 6]
IT Workshop: Test 1
41. What is the output of the following code? 44. What is the output of the following?
a={} x = "abcdef"
a[2]=1 while i in x:
a[1]=[2,3,4] print(i, end=" ")
print(a[1][1])
a) a b c d e f
a) [2,3,4]. b) abcdef
b) 3 c) i i i i i i …
c) 2 d) error
d) An exception is thrown.
45. What is the output of the following code?
42. What Will Be The Output Of The Following Code
Snippet? a=[1,2,3,4]
b=[sum(a[0:x+1]) for x in
box = {} range(0,len(a))]
jars = {} print(b)
crates = {}
box['biscuit'] = 1 a) 10
box['cake'] = 3 b) [1,3,5,7].
jars['jam'] = 4 c) 4
d) [1,3,6,10].
crates['box'] = box
crates['jars'] = jars 46. What is the output of the following piece of code?
print (len(crates[box]))
a=(2,3,1,5)
a) 1
a.sort()
b) 3
c) 4 print(a)
d) Type Error
a) (1,2,3,5)
43. What is the output of the following? b) (2,3,1,5)
c) None
d) Error, tuple has no attribute sort.
i = 0
while i < 5: 47. What is the output of the code shown below?
print(i)
i += 1 s1={3, 4}
if i == 3: s2={1, 2}
break s3=set()
else: i=0
print(0) j=0
for i in s1:
a) 0 1 2 0
for j in s2:
b) 0 1 2
c) error s3.add((i,j))
d) none of the mentioned. i+=1
j+=1
print(s3)
6|Page
Indian Institute of Information Technology, Nagpur.
IT Workshop: Test 1
a) [x**3 for x in l]
b) [x^3 for x in l]
c) [x**3 in l]
d) [x^3 in l]
a) Error
c) 1 4 7
258
369
d) (1 4 7)
(2 5 8)
(3 6 9)
a={}
a.fromkeys([1,2,3],"check")
a) Syntax error
b) {1:”check”,2:”check”,3:”check”}
c) “check”
d) {1:None,2:None,3:None}.
7|Page