NEW
Font size
WorksheetsPython Ch. 11- Review
Total questions: 16
Worksheet time: 8mins
Python syntax is primarily focused on creating which of the following?
Code blocks
Functions
Objects
None of these options
The following syntax is used when creating a class:
class def Fruit
True
False
The following syntax is used to initialize objects:
class Teams (object)
def __init__(self):
True
False
What will run when the following code is executed?
class Teams(object)
def __init__(self, name)
self.name = name
New_York = Teams ("Mets")
print New_York.name
New_York
Mets
New_York = Mets
New York = "Mets"
Variables that may be used throughout the code block are labeled...
Global Variables
Member Variables
Instance Variables
Dependent Variables
The scope of a variable is the context in which it's visible to the program.
True
False
When a class has its own functions, those functions are called...
Member Variables
Global Variables
Methods
None of these options
The process by which one class takes on the attributes and methods of another is called...
Inheritance
Global Variables
__init__
None of these options
When creating classes, there are both parent and derived classes.
True
False
Which of the following classes is the parent class?
class Employee(object):
"""Models real-life employees!"""
def __init__(self, employee_name):
self.employee_name = employee_name
class PartTimeEmployee(Employee):
def calculate_wage(self, hours):
self.hours = hours
return hours * 12.00
Employee
Hours
PartTimeEmployee
None of these options
What will run when the following code is executed?
class Triangle(object):
number_of_sides = 3
def __init__(self, angle1, angle2, angle3):
self.angle1 = angle1
self.angle2 = angle2
self.angle3 = angle3
def check_angles(self):
if (self.angle1 + self.angle2 + self.angle3) == 180:
return True
else:
return False
my_triangle = Triangle(30, 60, 90)
print my_triangle.number_of_sides
print my_triangle.check_angles()
2, True
4, False
3, False
3, True
Is the following code written correctly when creating an Employee class?
class Employee(object):
"""Models real-life employees!"""
def __init__(self, employee_name):
self.employee_name = employee_name
True
False
What will run when the following code is executed?
lass Employee(object):
"""Models real-life employees!"""
def __init__(self, employee_name):
self.employee_name = employee_name
def calculate_wage(self, hours):
self.hours = hours
return hours * 20.00
class PartTimeEmployee(Employee):
def calculate_wage(self, hours):
self.hours = hours
return hours * 12.00
def full_time_wage(self, hours):
return super(PartTimeEmployee, self).calculate_wage(hours)
milton = PartTimeEmployee('Milton')
print milton.full_time_wage(10)
200.0
250.0
100.0
85.0
Is the following code correct when creating a Shape class?
class Shape(object):
"""Makes shapes!"""
def __init__(self, sides):
self.number_of_sides = number_of_sides
True
False
Which of the following variables is available to all parts of the class?
Global
Instance
Local
Member
In the following code block, which of the following lines utilize dot notation?
class Square(object):
def __init__(self):
self.sides = 4
class Square(object)
def __init__(self)
self.sides = 4
None of these options
