Font size
WorksheetsPrelim Summative Test
Total questions: 60
Worksheet time: 3600secs
How to create a single element tuple
(1,)
(1)
{1}
[1]
tuple([1])
Result of the program above is
('1', '2', '3', '4', '5')
(1, 2, 3, 4, 5)
12345
"12345"
What is the output of the program above
<class 'tuple'>
<class 'None'>
<class 'list'>
<class 'int'>
Let list1=[2,4,6,8,10] the print(list1[-2]) will result in
10
8
4
6
Which of the following will produce an error? e = (1,2,3)
e = (4, 5, 6)
e = e + 4
e = e + (4, 5, 6)
e = e + (4,)
What is the index of the following tuple: y = ()
0
1
There is none. It is an empty tuple
Can you have lists inside of tuples and vice versa?
Yes
No
What will be the output of the following Python code?
>>> a=(1,2,3,4)
>>> del(a[2])
Now, a=(1,2,4)
Now, a=(1,3,4)
Now a=(3,4)
Error as tuple is immutable
What is the difference between a tuple and a list in Python?
The main difference is that tuples are immutable and lists are mutable.
Tuples can be changed after creation, while lists cannot.
Lists are faster than tuples in all cases.
Tuples can only contain numbers, while lists can contain any data type.
t = ('a', 'b', 'c', 'd')
print(t.index('c'))
a, b, c = (1, 2, 3)
Error: too many values to unpack
To delete an entire tuple, the __________ command can be used.
remove
delete
del
erase
What will be the output of the following Python code?
>>> a=("Check")*3
>>> a
(‘Check’,’Check’,’Check’)
* Operator not valid for tuples
(‘CheckCheckCheck’)
Syntax error
What will be the output of the following Python code?
>>>my_tuple = (1, 2, 3, 4)
>>>my_tuple.append( (5, 6, 7) )
>>>print len(my_tuple)
1
2
5
Error
What is the output of the following
tuple1 = (1120, 'a')
print(max(tuple1))
typeerror
1120
'a'
none of the above
Choose the correct way to access value 20 from the following tuple
tuple1= ("Orange", [10, 20, 30], (5, 15, 25))
tuple1[1:2](1)
tuple1[1:2][1]
tuple1[1][1]
All of the above
Which of the following methods is used to reverse the elements of a tuple in Python?
reversed()
swap()
sort()
reverse()
What will be the output of the following Python code snippet?
tuple1 = (1, 2, 3)
tuple2 = (4, 5, 6)
result = tuple1 + tuple2
print(result) Copy Code
(1, 2, 3, 4, 5, 6)
(1, 2, 3), (4, 5, 6)
(4, 5, 6, 1, 2, 3)
Error: Unsupported operand types for +
Which of the following is not a function of the tuple?
max()
min()
count()
update()
Which of these is the correct code for creating a list of names?
nameList = John, Harry, Jesse, John, Harry, Harry
nameList = ("John", "Harry", "Jesse", "John", "Harry", "Harry")
nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]
nameList = [John, Harry, Jesse, John, Harry, Harry]
List items have an index number. In the following list, which item has the index number of 3?
["John", "Harry", "Jesse", "John", "Harry", "Harry"]
"John"
"Harry"
"Jesse"
Which of these pieces of code would return the name "Harry" from the following list?
nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]
nameList()
nameList[1]
NameList(4)
nameList["4"]
The list needs one more name added to the end - "Felipe". Which piece of code below would do this?
nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]
nameList.append(Felipe)
append(nameList,"Felipe")
nameList.append["Felipe",7]
nameList.append("Felipe")
What would this code show on the screen?
7
6
5
4
An error
What would this code return on the shell?
Nothing
An error
"Woo hoo, you scored!"
"Raheem"
What is the index number for 'Spain'?
['England','Brazil','Spain','France']
0
1
2
3
Which code would i use to add an item to a list?
variable.add()
variable.append()
append.variable()
add.variable()
What is used to separate elements in a list?
Bracket
Comma
Full Stop
Space
What brackets are used to create a list?
()
[]
What does the '#' allow you to do?
Repeat code
Comment on code
Print code
End code
Which of these operators means EQUAL TO?
'='
'=>'
'<='
'=='
If you want to create an empty list called islands, which of the following pieces of code is correct?
islands = { }
islands = ( )
islands = [ ]
islands = < >
Is this the correct code for a list?
register = {"Sam", "Pheobe", Georgia", Richard"}
Yes
No
What is the index of “grape” in the list
[“apple”, “grape”, “orange”, “watermelon”]?
0
1
2
3
What is the output of program below?
motorcycles = ['honda', 'yamaha', 'suzuki']
motorcycles.sort()
print(motorcycles)
['honda', 'yamaha', 'suzuki']
['yamaha', 'suzuki', 'honda']
['honda', 'suzuki', 'yamaha']
['suzuki', 'yamaha', 'honda']
names = ["Paul","Phillip","Paula","Phillipa"]
Q: What does the code print?
der eulb wolley neerg
r b y g
green
red blue yellow green
re blu yello gree
Q: What does the code print?
0 red: 1 blue: 2 yellow: 3 green:
0 r: 1 b: 2 y: 3 g:
1 blue: 3 green: 2 yellow: 0 red:
1 b: 3 gre: 2 ye: 0 :
Q: What does the code print?
0
blue
b
None
Q: What does the code print?
x 0
x 3
li 3
li 0
None of the above
Q: What does the code print?
x 0
a 3
c 1
c 3
None of the above
Q: What does the code print?
0 1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
0 1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
Q: What does the code print?
1 4 7
1 4 8
1 3 5 7
1 3 5 7 9
Q: What does the code print?
['basketball'] [''basketball', 'softball'] ['baseball', 'swimming'
['basketball'] ['tennis', 'basketball', 'softball'] ['baseball']
['basketball'] ['tennis', 'basketball', 'softball'] ['baseball', 'swimming']
None of the above
Q: What does the code print?
['softball']
te ba so gy so ba sw
['tennis', 'basketball']
ten bas sof gym soc bas swi
None of the above
Q: What does the code print?
['tenni', 'baketball', 'oftball', 'gymnatic', 'occer', 'baeball', 'wimming']
[]
['basketball', 'softball', 'soccer', 'baseball']
None of the above
Q: What does the code print?
I love python
[I, love, python]
['I', 'love', 'python']
None of the above
Q: What does the code print?
ystery quiz
mystery quiz
yst qui
mystery qui
ystery qui
quiz = {"Do you help out at home? ":"yes",
"Do you beleive in Santa? ":"yes"}
Given the dictionary person = {"name": "Alice", "age": 30}, how would you access Alice's age?
person[age]
person["Alice", "age"]
person.age
person["age"]
Suppose d = {“john”:40, “peter”:45}, to delete the entry for “john” what command do we use?
d.delete(“john”:40)
d.delete(“john”)
del d[“john”]
del d(“john”:40)
What will be the output of the following Python code snippet?
d = {"john":40, "peter":45}
d["john"]
40
45
“john”
“peter”
Items are accessed by their position in a dictionary and All the keys in a dictionary must be of the same type.
True
False
Select the all correct way to remove the key ‘marks‘ from a dictionary
student = { "name": "Emma", "class": 9, "marks": 75 }
student.pop(“marks”)
del student[“marks”]
student.popitem()
dict1.remove(“key2”)
What is the output of the following dictionary operation
dict1 = {"name": "Mike", "salary": 8000}
temp = dict1.get("age")
print(temp)
KeyError: ‘age’
None
Select correct ways to create an empty dictionary
sampleDict = {}
sampleDict = dict()
sampleDict = dict{}
sampleDict = ()
