wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Final

Total questions: 128

Worksheet time: 2hrs 42mins

Name
Class
Date
1.
Look at this code, how many times will it loop?
a)
50
b)
90
c)
0
d)
4
2.
What is another way of writing the following code? 
Score = Score + 1 
a)
Score.add(1)
b)
score + 1
c)
Score + Score
d)
Score += 1
3.
What are the two main types of loops that we have learned about in Python?
a)
IF Function & Variables
b)
FOR and WHILE Loops
c)
Forever and Fixed Loop
d)
Data Types and Numbers
4.
What is the word used to describe repetition in programming?
a)
Sequence
b)
Selection
c)
Iteration
d)
Coding
5.

The program above

a)

prints all the odd numbers between 1 and 20

b)

prints all even numbers between 1 and 20

c)

print all the odd numbers between 1 and 21

d)

prints all the even numbers between 1 and 21

6.

for i in 100 :

print ( i )

a)

Syntax error

b)

prints numbers 0 to 100

c)

prints numbers 1 to 100

d)

prints numbers 0 to 99

e)

prints numbers 1 to 99

7.

Repeats a statement or group of statements while a given condition is TRUE. It tests the condition before executing the loop body.

a)

while loop

b)

for loop

c)

nested loop

d)

infinite loop

8.

Executes a sequence of statements multiple times and abbreviates the code that manages the loop variable.

a)

while loop

b)

for loop

c)

nested loop

d)

infinite loop

9.

What does the code print?

a)

10

7

4

1

Done

b)

10

9

8

7

6

5

4

3

2

1

Done

c)

Done

d)

10

7

4

1

-2

-5

... and more, running infinitely.

10.
Why is iteration important?
a)
It determines the order in which instructions are carried out
b)
It allows code to be simplified by removing duplicated steps
c)
It allows multiple paths through a program
11.
What will print?
a)
nothing
b)
5
c)
6
d)
an error message
12.
How many times will Boo print?
a)
none
b)
4
c)
5
d)
1
13.

Which of the following keywords marks the begining of the function block?

a)

Func

b)

define

c)

def

d)

function

14.

Which of the following items are present in the function header?

a)

Function name only

b)

Both function name and parameter list

c)

parameter list only

d)

Return value

15.

What is the default return value for a function that does not return a value explicitly?

a)

None

b)

int

c)

double

d)

null

16.

What term is used to describe data passed into/out of a program?

a)

Variable

b)

Loop

c)

Constant

d)

Parameter

17.

Consider the line of code:

Label('Go Team', 200, 100)

What is the Label?

a)

argument

b)

parameter

c)

function name

18.

Rewrite this line of code correctly!

(a)  

19.

When defining a function, the definition must occur before it is called.

a)

true

b)

false

20.

What does the following code output?

a)

11, 9

b)

16, 16

c)

None, None

d)

225, 117

21.

What is a class (in python)?

a)

A user-defined prototype for an object that defines a set of attributes that characterize any object of this. The attributes are data members and methods, accessed via dot notation.

b)

A special kind of function that is defined in a class definition.

c)

The assignment of more than one behavior to a particular function. The operation performed varies by the types of objects or arguments involved.

d)

the system of ordering a society in which people are divided into sets based on perceived social or economic status.

22.

What is a class variable (in python)?

a)

A user-defined prototype for an object that defines a set of attributes that characterize any object of the class. The attributes are data members (class variables and instance variables) and methods, accessed via dot notation.

b)

A variable that is shared by all instances of a class. Class variables are defined within a class but outside any of the class's methods. Class variables are not used as frequently as instance variables are.

c)

A student

d)

A part of a class that exists like a desk or a smartboard

23.

What is a data member (in python)?

a)

A class variable or instance variable that holds data associated with a class and its objects.

b)

a person who is part of the club DATA

c)

A variable that is defined inside a method and belongs only to the current instance of a class.

d)

An individual object of a certain class. An object obj that belongs to a class Circle, for example, is an instance of the class Circle.

24.

What is an instance variable (in python)?

a)

An individual object of a certain class. An object obj that belongs to a class Circle, for example, is an instance of the class Circle.

b)

A variable that is defined inside a method and belongs only to the current instance of a class.

c)

The transfer of the characteristics of a class to other classes that are derived from it.

d)

A special kind of function that is defined in a class definition.

25.
What will print?
a)
nothing
b)
5
c)
6
d)
an error message
26.
What will print?
a)
nothing
b)
7
c)
z
d)
12
27.

What term is used to describe data passed into a function?

a)

Variable

b)

Loop

c)

Constant

d)

Parameter

28.

people = ["John", "Rob", "Bob"]

print (people[4])

what would this result be?

a)
John
b)
Rob
c)
Bob
d)
Error
29.

_____ represents an entity in the real world with its identity and behaviour.

a)

A method

b)

An object

c)

A class

d)

An operator

30.
What is the difference between a class and an object?
a)
A class is a blueprint to make an object
b)
An object is a blueprint to make a class
c)
A blueprint is an object to make a class
d)
Blueprint class is an object make a
31.

What is the process in which objects of one class can link and share some common properties from the objects of another class?

a)

Abstraction

b)

Inheritance

c)

Polymorphism

d)

Encapsulation

32.

What is the process of using a function for more than one purpose that allows the use of different internal structures of the object by keeping the same external interface?

a)

Inheritance

b)

Polymorphism

c)

Abstraction

d)

Encapsulation

33.

What is an instance of or a copy of a class?

a)

Class

b)

Object

c)

Attribute

d)

Interface

34.

What is blue print that defines certain characteristics and behavior that is simply a representation of different types of objects?

a)

Class

b)

Object

c)

Attribute

d)

Characteristics

35.

A dog might be an instance of the Pet class?

a)

True

b)

False

36.

What is a method in python?

a)

a way of doing something

b)

a special kind of function that is defined in a class definition

c)

the creation of an instance of a class

d)

orderliness of thought or behavior; systematic planning or action

37.

What is the definition inheritance?

a)

The decleration of a new class without changing any previous behaviours

b)

A mechanism where a new class (subclass) inherits properties and behavior from an existing class (superclass).

c)

Taking the belogins of your child class

d)

The instances of a new class which contains new attributes and methods and only belongs in your file.

38.

What is polymorphism in OOP?

a)

Ability of an object to take on multiple roles

b)

Ability of an object to change its state

c)

Ability of an object to inherit from multiple classes

d)

Ability of an object to take on many forms

39.

A single object can also be referred to as an...

a)

Instance

b)

Object

c)

Singular

d)

Singular Object

40.

In a class, member variables are often called its _________, and its member functions are sometimes referred to as its behaviour, or ____________.

a)

data, activities

b)

attributes, activities

c)

attributes, activities

d)

attributes, methods

41.

What is encapsulation in OOP?

a)

Encapsulation is the process of hiding data and methods within a class.

b)

Encapsulation is the process of inheriting properties and methods from a parent class.

c)

Encapsulation is bundling data and methods together within a class.

d)

Encapsulation is the process of breaking down a class into smaller components.

42.

What is abstraction in OOP?

a)

Process of randomly selecting information to show to the user.

b)

Process of encrypting information to show to the user.

c)

Process of hiding unnecessary details and only showing essential information to the user.

d)

Process of showing all details to the user.

43.

What allows us to consider complex ideas while ignoring irrelevant detail that could confuse us?

a)

Abstraction

b)

Encapsulation

c)

Inheritance

d)

Polymorphism

44.

Which one(s) is/are an object?

a)

public class Rectangle

b)

Student ada = new Student();

c)

Rectangle rect = new Rectangle(10, 3);

d)

ada.reName();

45.

You can instantiate an object more than once?

a)

True

b)

False

46.

What is instantiation in python?

a)

The creation of an instance of a class.

b)

The transfer of the characteristics of a class to other classes that are derived from it.

c)

A variable that is defined inside a method and belongs only to the current instance of a class.

d)

A unique instance of a data structure that's defined by its class. An object comprises both data members (class variables and instance variables) and methods.

47.

What is the process of using a function for more than one purpose that allows the use of different internal structures of the object by keeping the same external interface?

a)

Inheritance

b)

Polymorphism

c)

Abstraction

d)

Encapsulation

48.

Members are not allowed to be accessed outside the class

a)

Private

b)

Protected

c)

Static

d)

Public

49.

Given there's a class Car, the program would print what?

civic = Car("Honda", "Civic", 2020)

print(civic ._model)

a)

Civic

b)

Honda

c)

2020

d)

None

50.
includes numbers and booleans
a)
data types
b)
whitespace
c)
modulo
d)
comments
51.
used to structure code in Python
a)
whitespace
b)
comments
c)
booleans
d)
variables
52.
runs code line by line and checks for errors
a)
interpreter
b)
variable
c)
modulo
d)
boolean
53.
Used to create exponents
a)
**
b)
"""
c)
%
d)
#
54.
stores a piece of data, and gives it a specific name
a)
variable
b)
whitespace
c)
interpreter
d)
modulo
55.
returns the remainder from division
a)
modulo
b)
exponments
c)
boolean
d)
variables
56.
surrounds multi-line comments
a)
"""
b)
**
c)
#
d)
%
57.
a line of text that Python won't try to run as code
a)
comment
b)
modulo
c)
variable
d)
boolean
58.
symbol used for modulo
a)
%
b)
&
c)
#
d)
**
59.
a data type than can have one of two values: True or False
a)
boolean
b)
variable
c)
modulo
d)
interpreter
60.
changing the value of a variable
a)
reassign
b)
comment
c)
modulo
d)
boolean
61.
Used to make comments
a)
#
b)
%
c)
**
d)
()
62.
The correct way to write a variable in Python?
a)
my_variable = 10
b)
my variable = 10
c)
my_variable is 10
d)
my_variable: 10
63.
10= 100
Which of the following is used in Python to calculate ten squared?
a)
10 ** 2
b)
10 * 2
c)
10 % 2
d)
10 ** 10
64.
The second part of if, that is executed when the condition is false
a)
if
b)
else
c)
for
d)
input
65.
What will the lines of code print?
a)
A
b)
B C
c)
A B C
d)
A C
66.
What will the following lines of code print?
a)
A
b)
B C
c)
A C
d)
Nothing, it will return an error.
67.
Which statement will check to see if a is equal to b?
a)
if a == b
b)
if a = b:
c)
if a != b:
d)
if a == b:
68.

Pieces of code that only run "under certain conditions":

a)

conditional statements

b)

control flow statments

c)

syntax

d)

variables

69.

If you want to test more than one condition (chained condition), what do you use after if statement?

a)

elif

b)

else

c)

ifif

d)

else if

70.

‘If’ is a decision making statement

a)

TRUE

b)

FALSE

71.

Which of the following conditions tell me to sleep if my alarm did not go off (alarm = False) and I’m tired (tired = True)?

Both alarm and tired default assignment is True.

a)

b)

c)

d)

72.

How can you check if a value is NOT equal to a specific value in Python's if statement?

a)

Use the != operator

b)

Use the == operator

c)

Use the <> operator

d)

Use the <= operator

73.

What will print when this program is executed?

a)

You need an umbrella.

b)

You do not need an umbrella.

c)

True

d)

False

e)

Nothing will print

74.

A Python dictionary stores ...

a)

value - key pairs

b)

key - value pairs

75.

A dictionary is an example of a sequence ...

a)

True

b)

False

76.
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
77.
Which symbol surrounds a dictionary?
a)
{
b)
(
c)
[
d)
:
78.
is this code correct?
quiz = ("Do you help out at home? ":"yes"      }
a)
No
b)
Yes
c)
Both
79.

thisList = ["square", "circle", "triangle", "octagon"]

thisNumList = [1, 500, 21.7]

print(thisList)

print(thisNumList)

a)

['square', 'circle', 'triangle', 'octagon']

[1, 500, 21.7]

b)

['square', 'circle', 'triangle', 'octagon']

c)

[1, 500, 21.7]

d)

['square', 'rectangle', 'triangle', 'octagon']

80.

thisList = ["square", "circle", "triangle", "octagon"]

print(thisList[3])

a)

octagon

b)

triangle

c)

circle

d)

square

81.

thisList = ["square", "circle", "triangle", "octagon"]

thisList[1] = "rectangle"

print(thisList)

a)

['square', 'rectangle', 'triangle', 'octagon']

b)

["square", "circle", "triangle", "octagon"]

c)

["square", "triangle", "octagon"]

d)

square

circle

triangle

octagon 

82.

thisList = ["square", "circle", "triangle", "octagon"]

if "triangle" in thisList:

print("Yes, 'triangle' is in the list")

else:

print("No triangle here!")

a)

Yes, 'triangle' is in the list

b)

"No triangle here!"

83.

thisList = ["square", "circle", "triangle", "octagon"]

thisList.insert(1, "rectangle")

print(thisList)

a)

['square', 'rectangle', 'circle', 'triangle', 'octagon']

b)

["square", "circle", "triangle", "octagon"]

c)

'square', 'circle', 'octagon']

d)

squarecircletriangleoctagon

84.

thisList = ["square", "circle", "triangle", "octagon"]

for x in thisList:

print(x)

a)

square

circle

triangle

octagon 

b)

square

circle

triangle

c)

"square", "circle", "triangle", "octagon"

d)

square circle triangle octagon 

85.

thisList = ["square", "circle", "triangle", "octagon"]

thisList.remove("triangle")

print(thisList)

a)

['square', 'circle', 'octagon']

b)

["square", "circle", "triangle", "octagon"]

c)

[ "triangle" ]

d)

['square', 'rectangle', 'triangle', 'octagon']

86.

myList = ['a', 'b', 'd', 'e', 'l']

myList.______________

print(myList)

OUTPUT: []

a)

copy()

b)

clear()

c)

extend()

d)

remove

87.

myList = ['a', 'k', 'b', 'z', 'l']

myList.______________

print(myList)

output ['a', 'b', 'k', 'l', 'z']

a)

sort()

b)

clear()

c)

append()

d)

remove()

88.

myList = ['a', 'k', 'b', 'z', 'l']

myList.______________

print(myList)

OUTPUT: ['l', 'z', 'b', 'k', 'a']

a)

reverse()

b)

count()

c)

sort()

d)

remove()

89.

myList = ['a', 'k', 'b', 'z', 'l']

val = myList.index('b')

print(val)

a)

1

b)

2

c)

3

d)

4

90.

myList = ['a', 'k', 'b', 'z', 'l']

val = len(myList)

print(val)

a)

3

b)

4

c)

5

d)

6

91.

myList = ['a', 'k', 'b', 'm']

myList.insert(1, 's')

print(myList)

a)

['a', 'k', 'b', 'm']

b)

['s', 'a', 'k', 'b', 'm']

c)

['a', 's', 'k', 'b', 'm']

d)

['s', 'k', 'b', 'm']

92.

myList = [1, 2, 3, 4, 5]

myList.pop(2)

print(myList)

a)

[1, 2, 3, 4, 5]

b)

[2, 3, 4, 5]

c)

[1, 3, 4, 5]

d)

[1, 2, 4, 5]

93.

myList = [1, 2, 3, 4, 5]

yourList = ['a', 'b', 'c']

myList.extend(yourList)

print(myList)

a)

[1, 2, 3, 4, 5, 'a', 'b', 'c']

b)

[1, 'a', 2, 'b', 3, 'c' 4, 5]

c)

[ 'a', 'b', 'c', 1, 2, 3, 4, 5]

d)

[ 'a', 1, 'b', 2, 'c', 3, 4, 5]

94.

Tiffany is taking orders from her friends to pick up ice cream. What is Tiffany’s list after the following request?icecreamList = []

icecreamList.append("strawberry")

icecreamList.append("coconut")

icecreamList.append("pistachio")

icecreamList.append("chocolate")

icecreamList.remove("coconut")

icecreamList.pop()

icecreamList.append("mango")

a)

strawberry, coconut, pistachio

b)

strawberry, pistachio, mango

c)

strawberry, pistachio, coconut

d)

strawberry, pistachio, chocolate

95.

The Game Club keeps track of player ranks by updating the leaderboard every day. After the following activities, what does the leaderboard look like?

leaderBoard = ["Heather", "Nia", "Cody"]

leaderBoard.append("Malik") l

eaderBoard.append("Carly")

leaderBoard.insert(1, "Aisha")

leaderBoard.insert(1, "Sabina")

leaderBoard.remove("Cody")

leaderBoard.pop()

a)

 Heather, Nia, Cody, Malik

b)

 Heather, Malik, Carly, Aisha, Sabina

c)

Heather, Aisha, Sabina, Nia, Malik,

d)

 Heather, Sabina, Aisha, Nia, Malik

96.

Which code segment when inserted in the blank will print the value of the key "Year".

birthday = {

"Month": "January",

"Day": "01",

"Year":2006

} print( __________________ )

a)

"Year"

b)

birthday[2006]

c)

birthday[Year]

d)

birthday["Year"]

97.

Which code segment when inserted in the blank sets the "Year" from 2006 to 2008?

birthday = {

"Month": "January",

"Day": "01",

"Year":2006

}

__________________________________

OUTPUT: 2008

a)

birthday["Year"]=2008

b)

birthday[Year]=2008

c)

birthday [2008]

d)

birthday[2006]=2008

98.

What will this code do?

birthday = {

"Month": "January",

"Day": "01",

"Year":2006

}

for x in birthday:

print(x)

a)

Prints all the key names in the dictionary

b)

print all the key and value pairs is the dictionary

99.

What is the output of the following code

dict1 = {"key1":1, "key2":2}

dict2 = {"key2":2, "key1":1}

print(dict1 == dict2)

a)

True

b)

False

100.

Select correct ways to create an empty dictionary

a)

sampleDict = {}

b)

sampleDict = dict()

c)

sampleDict = dict{}

101.

Please select all correct ways to empty the following dictionary

student = {

"name": "Emma",

"class": 9,

"marks": 75

}

a)

del student

b)

del student[0:2]

c)

student.clear()

102.

Items are accessed by their position in a dictionary

a)

True

b)

False

103.

Dictionary keys must be immutable

a)

True

b)

False

104.

In Python, Dictionaries are immutable

a)

True

b)

False

105.

________________method removes all items from the particular dictionary.

a)

clear( )

b)

pop( )

c)

del ( )

106.

_______________this method deletes the item from the dictionary

a)

pop( )

b)

del( )

c)

clear( )

107.

________________method will returns number of key-value pairs in the given dictionary.

a)

len( )

b)

pop( )

c)

del( )

d)

keys( )

e)

values( )

108.

Which of the following are true of Python dictionaries:

a)

Dictionaries can be nested to any depth.

b)

Dictionaries are accessed by key.

c)

All the keys in a dictionary must be of the same type.

d)

Dictionaries are mutable.

e)

A dictionary can contain any object type except another dictionary.

109.

Suppose you have a dictionary d1. Which of the following effectively creates a variable d2 which contains a copy of d1:

a)

d2 = dict(d1.items())

b)

d2 = dict(d1.keys())

c)

d2 = {}

d2.update(d1)

d)

d2 = dict(d1.values())

e)

d2 = dict(d1)

110.

What would be the output of the following code snippet?


a_dict = {'color': 'blue', 'fruit': 'apple', 'pet': 'dog'}


for key in a_dict:

print(key)

a)

'blue'

'apple'

'dog'

b)

color

fruit

pet

c)

blue

apple

dog

d)

'color'

'fruit'

'pet'

111.

What would be the output of the following code snippet?


a_dict = {'color': 'blue', 'fruit': 'apple', 'pet': 'dog'}

d_items = a_dict.items()

print(d_items)

a)

('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')

b)

dict_items([('color'), ('fruit'), ('pet')])

c)

[('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')]

d)

dict_items([('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')])

112.

Consider the following statement:


If you just need to work with the keys of a dictionary, then you can use .keys(), which is a method that returns a new view object containing the dictionary’s keys.


Is this statement True or False?

a)

False

b)

True

113.

A dictionary is an example of a sequence ...

a)

True

b)

False

114.

A Python dictionary stores ...

a)

value - key pairs

b)

key - value pairs

115.
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
116.
Which symbol surrounds a dictionary?
a)
{
b)
(
c)
[
d)
:
117.
is this code correct?
quiz = ("Do you help out at home? ":"yes"      }
a)
No
b)
Yes
c)
Both
118.

Which of the following will give error?

Suppose dict1={"a":1,"b":2,"c":3}

a)

print(len(dict1))

b)

print(dict1.get("b"))

c)

dict1["a"]=5

d)

None of these.

119.

What is the extension of python library modules?

a)

.mod

b)

.lib

c)

.code

d)

.py

120.

How many times will it print "#"?

a)

1

b)

2

c)

3

d)

4

121.

What is the output of this code when "robert" is entered by the user when prompted?

a)

True

b)

error

c)

Robert

d)

False

122.

What is the output when the following code snippet is run:

a)

Error

b)

None

c)

Let's enjoy a bowl of cereals

d)

Groceries trip pending

123.

What will the output be after executing the following code?

a)

[6]

b)

[0, 1, 2, 3, 4, 5]

c)

-6

d)

(0,1,2,3,4)

124.

What will the output be after running the following code?

a)

[0,1,2,3,4,5]

b)

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

c)

[0, 1, 2, 3, 4, 6]

d)

[1,2,3,4,5,6]

125.

What will the output be, if we run the following code?

a)

0 1

1 1

0 0

1 0

b)

0 1

0 0

1 1

1 0

c)

0 1

0 0

1 0

1 1

d)

0 1

1 1

1 0

0 0

126.

What will the output be after running the following code snippet?

a)

Robert method karamagi

b)

Robert method Karamagi

c)

Robert Method Karamagi

d)

ROBERT METHOD KARAMAGI

127.

What will the output be after calling the following function?

a)

6

b)

Syntax Error

c)

6 5

d)

5

128.

What will the output be after running the following code snippet?

a)

19

b)

Syntax Error

c)

True

d)

False