Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 47

1. What is the output of the following?

for i in range(10):
if i == 5:
break
else:
print(i)
else:
print("Here")

a) 0 1 2 3 4 Here
b) 0 1 2 3 4 5 Here
c) 0 1 2 3 4
d) 1 2 3 4 5
2. What is the output of the following?

x = (i for i in range(3))
for i in x:
print(i)

a) 0 1 2
b) error
c) 0 1 2 0 1 2
d) none of the mentioned
3. What is the output of the following?

string = "my name is x"


for i in string.split():
print (i, end=", ")

a) m, y, , n, a, m, e, , i, s, , x,
b) m, y, , n, a, m, e, , i, s, , x
c) my, name, is, x,
d) error
4. What is the output of the following?

a = [0, 1, 2, 3]
i = -2
for i not in a:
print(i)
i += 1

a) -2 -1
b) 0
c) error
d) none of the mentioned
5. Write a list comprehension
equivalent for the code shown below:

for i in range(1, 101):


if int(i*0.5) == i*0.5:
print(i)

a) [i for i in range(1, 100) if int(i*0.5)==(i*0.5)]


b) [i for i in range(1, 101) if int(i*0.5)==(i*0.5)]
c) [i for i in range(1, 101) if int(i*0.5)=(i*0.5)]
d) [i for i in range(1, 100) if int(i*0.5)=(i*0.5)]
6. What is the output of the code shown
below?

l = ["good", "oh!", "excellent!", "#450"]


[n for n in l if n.isalpha() or n.isdigit()]

a) [‘good’, ‘oh’, ‘excellent’, ‘450’ ]


b) [‘good’]
c) [‘good’, ‘#450’]
d) [‘oh!’, ‘excellent!’, ‘#450’]
7. What is the output of the code shown below?

s1=[3, 4]
s2=[1, 2]
s3=list()
i=0
j=0
for i in s1:
for j in s2:
s3.append((i,j))
i+=1
j+=1
print(s3)

a) {(3, 4), (1, 2)}


b) Error
c) [(3, 1), (4, 2), (4, 1), (5, 2)]
d) [(3, 1), (4, 2)]
8.What is the output of the following code?

a={}
a[2]=1
a[1]=[2,3,4]
print(a[1][1])

a) [2,3,4].
b) 3
c) 2
d) An exception is thrown
9.What is the output of the following code?

a={1:"A",2:"B",3:"C"}
for I , j in a.items():
print(i , j , end = " ")

a) 1A 2B 3C
b) 123
c) ABC
d) 1:”A” 2:”B” 3:”C”
10.What is the output of the following code?

a={1:"A",2:"B",3:"C"}
b={4:"D",5:"E"}
a.update(b)
print(a)

a) {1: ‘A’, 2: ‘B’, 3: ‘C’}


b) Method update() doesn’t exist for dictionaries
c) {1: ‘A’, 2: ‘B’, 3: ‘C’, 4: ‘D’, 5: ‘E’}
d) {4: ‘D’, 5: ‘E’}
11.What is the output of the following code?

a={1:"A",2:"B",3:"C"}
a.clear()
print(a)

a) None
b) { None:None, None:None, None:None}
c) {1:None, 2:None, 3:None}
d) {}
12.What is the output of the following code?

a={1:5,2:3,3:4}
a.pop(3)
print(a)

a) {1: 5}
b) {1: 5, 2: 3}
c) Error, syntax error for pop() method
d) {1: 5, 3: 4}
13. Consider the code:
lamb = lambda x: x ** 3
print(lamb(5))

a)25
b)15
c)error
d)125
14. What is the shortest way to
remove duplicate elements in a
list?

a)set
b)while
c)int
d)none
15. Which are the two built-in functions to
read a line of text from standard input,
which by default comes from the keyboard?

a) Raw_input & Input


b) Input & Scan
c) Scan & Scanner
d) Scanner
16. Is Python case sensitive when dealing with identifiers

a) yes
b) no
c) machine dependent
d) none of the mentioned
17. Which of the following is an invalid variable?

a) my_string_1
b) 1st_string
c) foo
d) _
18. Which of the following is an invalid statement?

a) abc = 1,000,000
b) a b c = 1000 2000 3000
c) a,b,c = 1000, 2000, 3000
d) a_b_c = 1,000,000
19. Which of these in not a core data type?

a) Lists
b) Dictionary
c) Tuples
d) Class
20. Following set of commands are executed
in shell, what will be the output?
>>>str="hello"
>>>str[:2]
>>>

a) he
b) lo
c) olleh
d) hello
21. In python we do not specify types,it is
directly interpreted by the compiler, so
consider the following operation to be
performed.
>>>x = 13 ? 2
objective is to make sure x has a integer
value, select all that apply (python 3.xx)

a) x = 13 // 2
b) x = int(13 / 2)
c) x = 13 % 2
d) All of the mentioned
22. The following is displayed by a print
function call:

tom
dick
harry

Select all of the function calls that result in


this output

a) print(”’tom\ndick\nharry”’)
b) print(”’tomdickharry”’)
c) print(‘tom\ndick\nharry’)
d) print(‘tomdickharry’)
23 . What is the output of the following?

i=0
while i < 5:
print(i)
i += 1
if i == 3:
break
else:
print(0)

a) 0 1 2 0
b) 0 1 2
c) Error
d)none
24. What is the output of the following?

print("Hello {name1} and


{name2}".format(name1='foo',name='bin'))

a) Hello foo and bin


b) Hello {name1} and {name2}
c) Error
d) Hello and
25: What is the output of the following?
x=1
y=2
z=x
x=y
y=z
print(x,y)

a) 1 1
b) 2 1
c) 2 2
d) 1 2
e) error
26: What is the output of the following?
x=input()
y=input()
print(x+y)
Where x = 2 , y = 4

a) 6
b) 42
c) 24
d) Error: Str object can’t be added with each other.
e) Invalid syntax
27:What is the output of the following code:
x=int(input())
y=int(input())
x=x//y
y=y//x
print(y)
Where x = 2 and y = 4

a) 2
b) 4
c) Error
d) 0
e) Invalid syntax
28:What is the output of the following code?
x=int(input())
y=int(input())
x=x/y
y=y/x
print(y)
Where x = 4 and y = 2

a) 2
b) 1
c) 2.0
d) 1.0
e) Error
f) 4.0
29: what is the ouput of the following code?
x=int(input())
y=int(input())
x=x%y
x=x%y
y=y%x
print(y)
Where x = 2 and y = 4

a) 2
b) 4
c) 1
d) 0
e) Erroe : zero division error
30: what is the output:
z=y=x=1
print(x,y,z,sep='*')

a) ***111
b) 111***
c) 1*1*1
d) *1*1*1
e) *1*1*1*
31: What is the output of the following code:
x = 1 / 2 + 3 // 3 + 4 ** 2
print(x)

a) 9.5
b) 17
c) 18.5
d) 17.5
32:what is the output of the following:
i=0
while i <= 3 :
i += 2
print("*")

a) **
b) Infinite
c) ***
d) *
33: what is the ouput of the following:
i=0
while i <= 5 :
i += 1
if i % 2 == 0:
break
print("*")

a) *
b) **
c) ***
d) ****
34: what is the output?
for i in range(1):
print("#")
else:
print("#")

a) #
b) # #
c) None
d) Error: if condition is not define
35: what is the output of the following?
var = 0
while var < 6:
var += 1
if var % 2 == 0:
continue
print("#")

a) # # #
b) # #
c) #
d) # # # # # #
e) # # # #
36: what is the output of the following?
a=1
b=0
c=a&b
d=a|b
e=a^b
print(c + d + e)

a) 0
b) 1
c) 2
d) none
37: what is the output of the following?
lst = [3, 1, -2]
print(lst[lst[ -1]])

a) -2
b) 1
c) None
d) error
38: what is the output of the following ?
lst = [1,2,3,4]
print(lst[ -3: -2])

a) 2
b) 3
c) [2]
d) [3]
39: what is the output of the following?
vals = [0, 1, 2]
vals[0], vals[2] = vals[2], vals[0]
Vals

a) [2, 1, 0]
b) [0 , 1 , 2]
c) [ 1 , 2 , 0]
d) [2 , 0 , 1]
40: what is the output of the following:
l1 = [1,2,3]
l2 = []
for v in l1:
l2.insert(0,v)
print(l2)

a) [3,2,1]
b) [2,3,1]
c) [1,3,2]
d) [3,1,2]
41: what is the length of L?

L = [i for i in range(-1,2)]
L

a) 3
b) 2
c) [3]
d) [2]
42: what is the output of the following?
T = [[3-i for i in range (3)] for j in range (3)]
s=0
for i in range(3):
s += T[i][i]
print(s)

a) 6
b) 5
c) 7
d) 3
43: print(3 * 'abc' + 'xyz')

a)abcabcabcxyz
b)abcxyzabcabc
c) xyzxyzxyzabc
d)abcxyzabcxyzabcxyz
44: import math
a = (2**(2+3)*3 - (4**4)*3)
math.fabs(a)

a) -672
b) 693
c) 672.0
d) -131
e) 643.0
f) None of the above is correct
45: what is the output of the following?
a = "2"
b=3
c= a*b
print(c)

a) 23
b) 222
c) 333
d) 32
46: A list name “students” containg 200 elements in the list.
You have to slice the last five elements from the list.
You may select more then one answer. If you want….

a) [:-5]
b) [1:-5]
c) [-5:-1]
d) [0:-5]
e) [-5:]
f) [-5:0]
X = (7+5)* (2)**3
print(x)

a) 96
b)96.0
c)error
d)72.0

You might also like