Test Python
Test Python
” after
running?
1.
d = {'me': 1, 'you': 2, 'we': 3}
print('Boom!')
2.
while d > 3:
print('Boom!')
3.
while True:
print('Boom!')
4.
print('Boom!')
a)1
b)2
c)3
d)4
answer- a d
A = [1,2,3,4,5,6,7]
a)A.append([6,7])
b)A.extend([6,7])
c)A = A + [6,7]
d)A.insert(-1,[6,7])
answer- b c
a = [50,50,60,70,70,70]
b = set(a)
C = [50,70,50,60,40,10,30,30]
def test(lst):
if lst in b:
return 1
else:
return 0
a)50 60 70
b)50 70 50 60
c)50 50 60 70 70 70
d)50 60 70 70 70
answer- b
4)What would be the values of x, y, and z after the following code is run?
x = 0
y = 3
z = 0
while not x or not y:
x = x^y
y -= 1
z &= x
print(x, end=" ")
print(y, end=" ")
print(z, end=" ")
a)2 1 0
b)3 2 0
c)3 0 1
d)1 2 0
answer- b
answer- c
6)What will be the value of x at the end of each iteration in the given program if
executed?
x = 2
for i in range(0, 4):
if x%2:
x = x*2
else:
x = x+1
answer- d
C) dict3 = dict1.merge(dict2)
D) dict3 = dict1.copy()
dict3.update(dict2)
answer- d
a)'e'.split(input_string, 2)
b) input_string.split('e', 2)
c)'e'.split(input_string, maxsplit=2)
d)input_string.split('e', maxsplit=2)
answer- b d
strength = 20
if (???):
print("Male")
else:
print("Female")
Which of the options can be placed at ??? to get the required output if the
strength has no limit of value (no upper limit)?
a)strength<70
b)strength>70
c)strength>100
d)strength<100
answer- b
10)Which of the options are correct to get a new_list having elements of lst in
reversed order.
def get_reverse(lst):
new_lst = _____________
return new_lst
answer- a d
11)Which of the following code snippets is the correct way to access the value of
the "history" subject from the dictionary given below?
sampleDict = { "class":{ "student":{ "name":"Mike", "marks":{ "physics":70,
"history":80 } } } }
a)sampleDict['class']['student']['marks']['history']
b) sampleDict['class'][0]['marks']['history']
c)sampleDict['class']['student']['marks'][1]
d)None of these
answer- a
12)Which of the options adds the elements 'Dhoni' and 'Virat' to the end of the
given list?
players = ['Jadeja','Rahul','Rohit'].
a)players+='Dhoni Virat'
b)players[len(players):] = ['Dhoni', 'Virat']
c)players[-1:] = ['Dhoni', 'Virat']
d)players+=['Dhoni', 'Virat']
answer- b d
13)In the given code snippet, the code should return each sublist in the output
only if the element "Data" is present in the sublist. What will be the appropriate
code block from the options to complete the function get_sublist() such that it
returns the output as expected.
sublists = [ ]
__________________
return sublists
Options are:
a)for lst in lists:
for i in lst:
sublists.append(i)
b)for lst in lists:
for i in lst:
sublists.append(lst)
c)for lst in lists:
if keyword in lst:
sublists.append(lst)
d)for lst in lists:
if keyword in lst:
sublists.append(keyword)
answer- c
14)You have been given the following piece of code. Assume that x has already been
declared.
if x > 2:
x = x*2
if x > 4:
x = 0
print(x)
answer- d
list2[0] = 'Guava'
list3[1] = 'Kiwi'
total = 0
for ls in (list1, list2, list3):
if ls[0] == 'Guava':
total += 1
if ls[1] == 'Kiwi':
total += 20
a)63 Guava
b)22 Guava
c)22 Apple
d)63 Apple
answer- c