WorksheetsLAB03
Total questions: 7
Worksheet time: 7mins
What are the contents of names after executing the following code fragment?
names = ["Fritz"]
names.insert(1, "Ann")
names.insert(0, "Sue")
names.pop(2)
names.append("Lee")
['Fritz', 'Ann', 'Lee']
['Sue', 'Fritz', 'Lee']
['Lee', 'Sue', 'Fritz']
['Fritz', 'Sue', 'Lee']
What will be the output of the following code fragment?
a = [2, 2, 2, 2]
b = [1, 1, 1]
c = a+b
print(c)
This code will generate an error
[3, 3, 3, 2]
[1, 1, 1, 2, 2, 2, 2]
[2, 3, 3, 3]
[2, 2, 2, 2, 1, 1, 1]
What will be output of the following python code?
string1 = "ICS##104-Computer##Science##"
index = string1[string1.count("##")]
print(index)
Error
3
#
S
phrase = "212-ICS-Midterm"
d= len(phrase)
a = int(phrase[2]) -1
b = phrase.find('-')
c = phrase[8:]
print(d,a,b,c)
(a)
Which of the following statements create a dictionary?
d = {}
d = {"Ali":25, "Ahmed":22}
d=[]
d = {25:"Ali", 22:"Ahmed"}
What is the output after executing the following python code?
values = { "F": 55, "M": 31, "B": 16, "C": -2 }
print(values[1])
Error
'F': 55
31
'M': 31
What will be the output of the following Python code?
s={3, 4, 4, 3, 10, 10}
s.add(4)
s.remove(10)
print(len(s))
4
3
2
Error
