Font size
WorksheetsPython Final
Total questions: 128
Worksheet time: 2hrs 42mins
Score = Score + 1
The program above
prints all the odd numbers between 1 and 20
prints all even numbers between 1 and 20
print all the odd numbers between 1 and 21
prints all the even numbers between 1 and 21
for i in 100 :
print ( i )
Syntax error
prints numbers 0 to 100
prints numbers 1 to 100
prints numbers 0 to 99
prints numbers 1 to 99
Repeats a statement or group of statements while a given condition is TRUE. It tests the condition before executing the loop body.
while loop
for loop
nested loop
infinite loop
Executes a sequence of statements multiple times and abbreviates the code that manages the loop variable.
while loop
for loop
nested loop
infinite loop
What does the code print?
10
7
4
1
Done
10
9
8
7
6
5
4
3
2
1
Done
Done
10
7
4
1
-2
-5
... and more, running infinitely.
Which of the following keywords marks the begining of the function block?
Func
define
def
function
Which of the following items are present in the function header?
Function name only
Both function name and parameter list
parameter list only
Return value
What is the default return value for a function that does not return a value explicitly?
None
int
double
null
What term is used to describe data passed into/out of a program?
Variable
Loop
Constant
Parameter
Consider the line of code:
Label('Go Team', 200, 100)
What is the Label?
argument
parameter
function name
Rewrite this line of code correctly!
(a)
When defining a function, the definition must occur before it is called.
true
false
What does the following code output?
11, 9
16, 16
None, None
225, 117
What is a class (in python)?
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.
A special kind of function that is defined in a class definition.
The assignment of more than one behavior to a particular function. The operation performed varies by the types of objects or arguments involved.
the system of ordering a society in which people are divided into sets based on perceived social or economic status.
What is a class variable (in python)?
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.
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.
A student
A part of a class that exists like a desk or a smartboard
What is a data member (in python)?
A class variable or instance variable that holds data associated with a class and its objects.
a person who is part of the club DATA
A variable that is defined inside a method and belongs only to the current instance of a class.
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.
What is an instance variable (in python)?
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.
A variable that is defined inside a method and belongs only to the current instance of a class.
The transfer of the characteristics of a class to other classes that are derived from it.
A special kind of function that is defined in a class definition.
What term is used to describe data passed into a function?
Variable
Loop
Constant
Parameter
people = ["John", "Rob", "Bob"]
print (people[4])
what would this result be?
_____ represents an entity in the real world with its identity and behaviour.
A method
An object
A class
An operator
What is the process in which objects of one class can link and share some common properties from the objects of another class?
Abstraction
Inheritance
Polymorphism
Encapsulation
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?
Inheritance
Polymorphism
Abstraction
Encapsulation
What is an instance of or a copy of a class?
Class
Object
Attribute
Interface
What is blue print that defines certain characteristics and behavior that is simply a representation of different types of objects?
Class
Object
Attribute
Characteristics
A dog might be an instance of the Pet class?
True
False
What is a method in python?
a way of doing something
a special kind of function that is defined in a class definition
the creation of an instance of a class
orderliness of thought or behavior; systematic planning or action
What is the definition inheritance?
The decleration of a new class without changing any previous behaviours
A mechanism where a new class (subclass) inherits properties and behavior from an existing class (superclass).
Taking the belogins of your child class
The instances of a new class which contains new attributes and methods and only belongs in your file.
What is polymorphism in OOP?
Ability of an object to take on multiple roles
Ability of an object to change its state
Ability of an object to inherit from multiple classes
Ability of an object to take on many forms
A single object can also be referred to as an...
Instance
Object
Singular
Singular Object
In a class, member variables are often called its _________, and its member functions are sometimes referred to as its behaviour, or ____________.
data, activities
attributes, activities
attributes, activities
attributes, methods
What is encapsulation in OOP?
Encapsulation is the process of hiding data and methods within a class.
Encapsulation is the process of inheriting properties and methods from a parent class.
Encapsulation is bundling data and methods together within a class.
Encapsulation is the process of breaking down a class into smaller components.
What is abstraction in OOP?
Process of randomly selecting information to show to the user.
Process of encrypting information to show to the user.
Process of hiding unnecessary details and only showing essential information to the user.
Process of showing all details to the user.
What allows us to consider complex ideas while ignoring irrelevant detail that could confuse us?
Abstraction
Encapsulation
Inheritance
Polymorphism
Which one(s) is/are an object?
public class Rectangle
Student ada = new Student();
Rectangle rect = new Rectangle(10, 3);
ada.reName();
You can instantiate an object more than once?
True
False
What is instantiation in python?
The creation of an instance of a class.
The transfer of the characteristics of a class to other classes that are derived from it.
A variable that is defined inside a method and belongs only to the current instance of a class.
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.
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?
Inheritance
Polymorphism
Abstraction
Encapsulation
Members are not allowed to be accessed outside the class
Private
Protected
Static
Public
Given there's a class Car, the program would print what?
civic = Car("Honda", "Civic", 2020)
print(civic ._model)
Civic
Honda
2020
None
Which of the following is used in Python to calculate ten squared?
Pieces of code that only run "under certain conditions":
conditional statements
control flow statments
syntax
variables
If you want to test more than one condition (chained condition), what do you use after if statement?
elif
else
ifif
else if
‘If’ is a decision making statement
TRUE
FALSE
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.
How can you check if a value is NOT equal to a specific value in Python's if statement?
Use the != operator
Use the == operator
Use the <> operator
Use the <= operator
What will print when this program is executed?
You need an umbrella.
You do not need an umbrella.
True
False
Nothing will print
A Python dictionary stores ...
value - key pairs
key - value pairs
A dictionary is an example of a sequence ...
True
False
quiz = {"Do you help out at home? ":"yes",
"Do you beleive in Santa? ":"yes"}
quiz = ("Do you help out at home? ":"yes" }
thisList = ["square", "circle", "triangle", "octagon"]
thisNumList = [1, 500, 21.7]
print(thisList)
print(thisNumList)
['square', 'circle', 'triangle', 'octagon']
[1, 500, 21.7]
['square', 'circle', 'triangle', 'octagon']
[1, 500, 21.7]
['square', 'rectangle', 'triangle', 'octagon']
thisList = ["square", "circle", "triangle", "octagon"]
print(thisList[3])
octagon
triangle
circle
square
thisList = ["square", "circle", "triangle", "octagon"]
thisList[1] = "rectangle"
print(thisList)
['square', 'rectangle', 'triangle', 'octagon']
["square", "circle", "triangle", "octagon"]
["square", "triangle", "octagon"]
square
circle
triangle
octagon
thisList = ["square", "circle", "triangle", "octagon"]
if "triangle" in thisList:
print("Yes, 'triangle' is in the list")
else:
print("No triangle here!")
Yes, 'triangle' is in the list
"No triangle here!"
thisList = ["square", "circle", "triangle", "octagon"]
thisList.insert(1, "rectangle")
print(thisList)
['square', 'rectangle', 'circle', 'triangle', 'octagon']
["square", "circle", "triangle", "octagon"]
'square', 'circle', 'octagon']
squarecircletriangleoctagon
thisList = ["square", "circle", "triangle", "octagon"]
for x in thisList:
print(x)
square
circle
triangle
octagon
square
circle
triangle
"square", "circle", "triangle", "octagon"
square circle triangle octagon
thisList = ["square", "circle", "triangle", "octagon"]
thisList.remove("triangle")
print(thisList)
['square', 'circle', 'octagon']
["square", "circle", "triangle", "octagon"]
[ "triangle" ]
['square', 'rectangle', 'triangle', 'octagon']
myList = ['a', 'b', 'd', 'e', 'l']
myList.______________
print(myList)
OUTPUT: []
copy()
clear()
extend()
remove
myList = ['a', 'k', 'b', 'z', 'l']
myList.______________
print(myList)
output ['a', 'b', 'k', 'l', 'z']
sort()
clear()
append()
remove()
myList = ['a', 'k', 'b', 'z', 'l']
myList.______________
print(myList)
OUTPUT: ['l', 'z', 'b', 'k', 'a']
reverse()
count()
sort()
remove()
myList = ['a', 'k', 'b', 'z', 'l']
val = myList.index('b')
print(val)
1
2
3
4
myList = ['a', 'k', 'b', 'z', 'l']
val = len(myList)
print(val)
3
4
5
6
myList = ['a', 'k', 'b', 'm']
myList.insert(1, 's')
print(myList)
['a', 'k', 'b', 'm']
['s', 'a', 'k', 'b', 'm']
['a', 's', 'k', 'b', 'm']
['s', 'k', 'b', 'm']
myList = [1, 2, 3, 4, 5]
myList.pop(2)
print(myList)
[1, 2, 3, 4, 5]
[2, 3, 4, 5]
[1, 3, 4, 5]
[1, 2, 4, 5]
myList = [1, 2, 3, 4, 5]
yourList = ['a', 'b', 'c']
myList.extend(yourList)
print(myList)
[1, 2, 3, 4, 5, 'a', 'b', 'c']
[1, 'a', 2, 'b', 3, 'c' 4, 5]
[ 'a', 'b', 'c', 1, 2, 3, 4, 5]
[ 'a', 1, 'b', 2, 'c', 3, 4, 5]
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")
strawberry, coconut, pistachio
strawberry, pistachio, mango
strawberry, pistachio, coconut
strawberry, pistachio, chocolate
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()
Heather, Nia, Cody, Malik
Heather, Malik, Carly, Aisha, Sabina
Heather, Aisha, Sabina, Nia, Malik,
Heather, Sabina, Aisha, Nia, Malik
Which code segment when inserted in the blank will print the value of the key "Year".
birthday = {
"Month": "January",
"Day": "01",
"Year":2006
} print( __________________ )
"Year"
birthday[2006]
birthday[Year]
birthday["Year"]
Which code segment when inserted in the blank sets the "Year" from 2006 to 2008?
birthday = {
"Month": "January",
"Day": "01",
"Year":2006
}
__________________________________
OUTPUT: 2008
birthday["Year"]=2008
birthday[Year]=2008
birthday [2008]
birthday[2006]=2008
What will this code do?
birthday = {
"Month": "January",
"Day": "01",
"Year":2006
}
for x in birthday:
print(x)
Prints all the key names in the dictionary
print all the key and value pairs is the dictionary
What is the output of the following code
dict1 = {"key1":1, "key2":2}
dict2 = {"key2":2, "key1":1}
print(dict1 == dict2)
True
False
Select correct ways to create an empty dictionary
sampleDict = {}
sampleDict = dict()
sampleDict = dict{}
Please select all correct ways to empty the following dictionary
student = {
"name": "Emma",
"class": 9,
"marks": 75
}
del student
del student[0:2]
student.clear()
Items are accessed by their position in a dictionary
True
False
Dictionary keys must be immutable
True
False
In Python, Dictionaries are immutable
True
False
________________method removes all items from the particular dictionary.
clear( )
pop( )
del ( )
_______________this method deletes the item from the dictionary
pop( )
del( )
clear( )
________________method will returns number of key-value pairs in the given dictionary.
len( )
pop( )
del( )
keys( )
values( )
Which of the following are true of Python dictionaries:
Dictionaries can be nested to any depth.
Dictionaries are accessed by key.
All the keys in a dictionary must be of the same type.
Dictionaries are mutable.
A dictionary can contain any object type except another dictionary.
Suppose you have a dictionary d1. Which of the following effectively creates a variable d2 which contains a copy of d1:
d2 = dict(d1.items())
d2 = dict(d1.keys())
d2 = {}
d2.update(d1)
d2 = dict(d1.values())
d2 = dict(d1)
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)
'blue'
'apple'
'dog'
color
fruit
pet
blue
apple
dog
'color'
'fruit'
'pet'
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)
('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')
dict_items([('color'), ('fruit'), ('pet')])
[('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')]
dict_items([('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')])
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?
False
True
A dictionary is an example of a sequence ...
True
False
A Python dictionary stores ...
value - key pairs
key - value pairs
quiz = {"Do you help out at home? ":"yes",
"Do you beleive in Santa? ":"yes"}
quiz = ("Do you help out at home? ":"yes" }
Which of the following will give error?
Suppose dict1={"a":1,"b":2,"c":3}
print(len(dict1))
print(dict1.get("b"))
dict1["a"]=5
None of these.
What is the extension of python library modules?
.mod
.lib
.code
.py
How many times will it print "#"?
1
2
3
4
What is the output of this code when "robert" is entered by the user when prompted?
True
error
Robert
False
What is the output when the following code snippet is run:
Error
None
Let's enjoy a bowl of cereals
Groceries trip pending
What will the output be after executing the following code?
[6]
[0, 1, 2, 3, 4, 5]
-6
(0,1,2,3,4)
What will the output be after running the following code?
[0,1,2,3,4,5]
(0,1,2,3,4,5,6)
[0, 1, 2, 3, 4, 6]
[1,2,3,4,5,6]
What will the output be, if we run the following code?
0 1
1 1
0 0
1 0
0 1
0 0
1 1
1 0
0 1
0 0
1 0
1 1
0 1
1 1
1 0
0 0
What will the output be after running the following code snippet?
Robert method karamagi
Robert method Karamagi
Robert Method Karamagi
ROBERT METHOD KARAMAGI
What will the output be after calling the following function?
6
Syntax Error
6 5
5
What will the output be after running the following code snippet?
19
Syntax Error
True
False
