wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Prelim Summative Test

Total questions: 60

Worksheet time: 3600secs

Name
Class
Date
1.

How to create a single element tuple

a)

(1,)

b)

(1)

c)

{1}

d)

[1]

e)

tuple([1])

2.

Result of the program above is

a)

('1', '2', '3', '4', '5')

b)

(1, 2, 3, 4, 5)

c)

12345

d)

"12345"

3.

What is the output of the program above

a)

<class 'tuple'>

b)

<class 'None'>

c)

<class 'list'>

d)

<class 'int'>

4.

Let list1=[2,4,6,8,10] the print(list1[-2]) will result in

a)

10

b)

8

c)

4

d)

6

5.

Which of the following will produce an error? e = (1,2,3)

a)

e = (4, 5, 6)

b)

e = e + 4

c)

e = e + (4, 5, 6)

d)

e = e + (4,)

6.

What is the index of the following tuple: y = ()

a)

0

b)

1

c)

There is none. It is an empty tuple

7.

Can you have lists inside of tuples and vice versa?

a)

Yes

b)

No

8.

What will be the output of the following Python code?


>>> a=(1,2,3,4)

>>> del(a[2])

a)

Now, a=(1,2,4)

b)

Now, a=(1,3,4)

c)

Now a=(3,4)

d)

Error as tuple is immutable

9.

What is the difference between a tuple and a list in Python?

a)

The main difference is that tuples are immutable and lists are mutable.

b)

Tuples can be changed after creation, while lists cannot.

c)

Lists are faster than tuples in all cases.

d)

Tuples can only contain numbers, while lists can contain any data type.

10.

t = ('a', 'b', 'c', 'd')

print(t.index('c'))

a)
1
b)
3
c)
4
d)
2
11.

a, b, c = (1, 2, 3)

a)
a=1, b=2, c=3
b)
a=3, b=2, c=1
c)
  • Error: too many values to unpack

d)
a=1, b=3, c=2
12.

To delete an entire tuple, the __________ command can be used.

a)

remove

b)

delete

c)

del

d)

erase

13.

What will be the output of the following Python code?


>>> a=("Check")*3

>>> a

a)

(‘Check’,’Check’,’Check’)

b)

* Operator not valid for tuples

c)

(‘CheckCheckCheck’)

d)

Syntax error

14.

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)

a)

1

b)

2

c)

5

d)

Error

15.

What is the output of the following
tuple1 = (1120, 'a') 

print(max(tuple1))

a)

typeerror

b)

1120

c)

'a'

d)

none of the above

16.

Choose the correct way to access value 20 from the following tuple
tuple1= ("Orange", [10, 20, 30], (5, 15, 25))

a)

tuple1[1:2](1)

b)

tuple1[1:2][1]

c)

tuple1[1][1]

d)

All of the above

17.

Which of the following methods is used to reverse the elements of a tuple in Python?

a)

reversed()

b)

swap()

c)

sort()

d)

reverse()

18.

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

a)

(1, 2, 3, 4, 5, 6)

b)

(1, 2, 3), (4, 5, 6)

c)

(4, 5, 6, 1, 2, 3)

d)

Error: Unsupported operand types for +

19.

Which of the following is not a function of the tuple?

a)

max()

b)

min()

c)

count()

d)

update()

20.

Which of these is the correct code for creating a list of names?

a)

nameList = John, Harry, Jesse, John, Harry, Harry

b)

nameList = ("John", "Harry", "Jesse", "John", "Harry", "Harry")

c)

nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]

d)

nameList = [John, Harry, Jesse, John, Harry, Harry]

21.

List items have an index number. In the following list, which item has the index number of 3?

["John", "Harry", "Jesse", "John", "Harry", "Harry"]

a)

"John"

b)

"Harry"

c)

"Jesse"

22.

Which of these pieces of code would return the name "Harry" from the following list?

nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]

a)

nameList()

b)

nameList[1]

c)

NameList(4)

d)

nameList["4"]

23.

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"]

a)

nameList.append(Felipe)

b)

append(nameList,"Felipe")

c)

nameList.append["Felipe",7]

d)

nameList.append("Felipe")

24.

What would this code show on the screen?

a)

7

b)

6

c)

5

d)

4

e)

An error

25.

What would this code return on the shell?

a)

Nothing

b)

An error

c)

"Woo hoo, you scored!"

d)

"Raheem"

26.

What is the index number for 'Spain'?

['England','Brazil','Spain','France']

a)

0

b)

1

c)

2

d)

3

27.

Which code would i use to add an item to a list?

a)

variable.add()

b)

variable.append()

c)

append.variable()

d)

add.variable()

28.

What is used to separate elements in a list?

a)

Bracket

b)

Comma

c)

Full Stop

d)

Space

29.

What brackets are used to create a list?

a)

()

b)

[]

30.

What does the '#' allow you to do?

a)

Repeat code

b)

Comment on code

c)

Print code

d)

End code

31.

Which of these operators means EQUAL TO?

a)

'='

b)

'=>'

c)

'<='

d)

'=='

32.

If you want to create an empty list called islands, which of the following pieces of code is correct?

a)

islands = { }

b)

islands = ( )

c)

islands = [ ]

d)

islands = < >

33.
What output will this code produce?
a)
blue
b)
green
c)
red
d)
error
34.

Is this the correct code for a list?

register = {"Sam", "Pheobe", Georgia", Richard"}

a)

Yes

b)

No

35.

What is the index of “grape” in the list

[“apple”, “grape”, “orange”, “watermelon”]?

a)

0

b)

1

c)

2

d)

3

36.
In the following code, "city" is an example of a what?
a)
List
b)
Loop
c)
Variable
d)
Array
37.
What output will this code produce?
a)
red
b)
['blue', 'green', 'red']
c)
['red', 'green', 'blue']
d)
error
38.

What is the output of program below?


motorcycles = ['honda', 'yamaha', 'suzuki']

motorcycles.sort()

print(motorcycles)

a)

['honda', 'yamaha', 'suzuki']

b)

['yamaha', 'suzuki', 'honda']

c)

['honda', 'suzuki', 'yamaha']

d)

['suzuki', 'yamaha', 'honda']

39.
What is the position of the name 'Paula' in the following list:
names = ["Paul","Phillip","Paula","Phillipa"]
a)
0
b)
1
c)
2
d)
3
40.

Q: What does the code print?

a)

der eulb wolley neerg

b)

r b y g

c)

green

d)

red blue yellow green

e)

re blu yello gree

41.

Q: What does the code print?

a)

0 red: 1 blue: 2 yellow: 3 green:

b)

0 r: 1 b: 2 y: 3 g:

c)

1 blue: 3 green: 2 yellow: 0 red:

d)

1 b: 3 gre: 2 ye: 0 :

42.

Q: What does the code print?

a)

0

b)

blue

c)

b

d)

None

43.

Q: What does the code print?

a)

x 0

b)

x 3

c)

li 3

d)

li 0

e)

None of the above

44.

Q: What does the code print?

a)

x 0

b)

a 3

c)

c 1

d)

c 3

e)

None of the above

45.

Q: What does the code print?

a)

0 1 2 3 4 5 6 7 8 9

b)

1 2 3 4 5 6 7 8 9

c)

0 1 2 3 4 5 6 7 8 9 10

d)

1 2 3 4 5 6 7 8 9 10

46.

Q: What does the code print?

a)

1 4 7

b)

1 4 8

c)

1 3 5 7

d)

1 3 5 7 9

47.

Q: What does the code print?

a)

['basketball'] [''basketball', 'softball'] ['baseball', 'swimming'

b)

['basketball'] ['tennis', 'basketball', 'softball'] ['baseball']

c)

['basketball'] ['tennis', 'basketball', 'softball'] ['baseball', 'swimming']

d)

None of the above

48.

Q: What does the code print?

a)

['softball']

b)

te ba so gy so ba sw

c)

['tennis', 'basketball']

d)

ten bas sof gym soc bas swi

e)

None of the above

49.

Q: What does the code print?

a)

['tenni', 'baketball', 'oftball', 'gymnatic', 'occer', 'baeball', 'wimming']

b)

[]

c)

['basketball', 'softball', 'soccer', 'baseball']

d)

None of the above

50.

Q: What does the code print?

a)

I love python

b)

[I, love, python]

c)

['I', 'love', 'python']

d)

None of the above

51.

Q: What does the code print?

a)

ystery quiz

b)

mystery quiz

c)

yst qui

d)

mystery qui

e)

ystery qui

52.
Which symbol surrounds a dictionary?
a)
{
b)
(
c)
[
d)
:
53.
What data type is this?
quiz = {"Do you help out at home? ":"yes",        
"Do you beleive in Santa? ":"yes"
}
a)
list
b)
string
c)
dictionart
d)
dictionary
54.

Given the dictionary person = {"name": "Alice", "age": 30}, how would you access Alice's age?

a)

person[age]

b)

person["Alice", "age"]

c)

person.age

d)

person["age"]

55.

Suppose d = {“john”:40, “peter”:45}, to delete the entry for “john” what command do we use?

a)

d.delete(“john”:40)

b)

d.delete(“john”)

c)

del d[“john”]

d)

del d(“john”:40)

56.

What will be the output of the following Python code snippet?

d = {"john":40, "peter":45}

d["john"]

a)

40

b)

45

c)

“john”

d)

“peter”

57.

Items are accessed by their position in a dictionary and All the keys in a dictionary must be of the same type.

a)

True

b)

False

58.

Select the all correct way to remove the key ‘marks‘ from a dictionary

student = { "name": "Emma", "class": 9, "marks": 75 }

a)

student.pop(“marks”)

b)

del student[“marks”]

c)

student.popitem()

d)

dict1.remove(“key2”)

59.

What is the output of the following dictionary operation

dict1 = {"name": "Mike", "salary": 8000}

temp = dict1.get("age")

print(temp)

a)

KeyError: ‘age’

b)

None

60.

Select correct ways to create an empty dictionary

a)

sampleDict = {}

b)

sampleDict = dict()

c)

sampleDict = dict{}

d)

sampleDict = ()