Font size
WorksheetsQuiz1_HPB2021_2010t1
Total questions: 10
Worksheet time: 20mins
What is the output of the following code:
x = 3
if 2 > x :
print 'First'
else :
print 'Second'
if 2 > x :
print 'Third'
print 'Fourth'
print 'Fifth'
Second
Fourth
Fifth
First
Second
Third
Fourth
Fifth
Fifth
First
Third
Fifth
1. Which of the below statements will create a Python list?
list1 = list()
list1 = []
list1 = list([1, 2, 3])
all of the mentioned
If list_example is [2, 33, 222, 14, 25], What is list_example[:-1]?
Error
25
[2, 33, 222, 14]
[25, 14, 222, 33, 2]
Find the output of the following Python code snippet:
print 'ab cd-ef'.title(),
Ab cd-ef
Ab Cd-ef
Ab Cd-Ef
None of the mentioned
Find the output of the following Python code snippet?
print('abcd'.translate({97: 98, 98: 99, 99: 100}))
bcde
abcd
error
none of the mentioned
Shortly explain why the output of the following Python code is 16?
count={}
count[(1,2,4)] = 5
count[(4,2,1)] = 7
count[(1,2)] = 6
count[(4,2,1)] = 2
tot = 0
for i in count:
tot=tot+count[i]
print(len(count)+tot)
output:16
Which of the statements about dictionary values is false?
More than one key can have the same value
The values of the dictionary can be accessed as dict[key]
Values of a dictionary must be unique
Values of a dictionary can be a mixture of letters and numbers
What happens when you run the code and what will be the output of the following Python code?
i = 1
while False:
if i%2 == 0:
break
print(i)
i += 2
What arithmetic operators cannot be used with strings?
+
*
-
All of the mentioned
What will be the output of the following Python code?
>>>str1="helloworld"
>>>str1[::-1]
dlrowolleh
hello
world
helloworld
