wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python Ch. 11- Review

Total questions: 16

Worksheet time: 8mins

Name
Class
Date
1.

Python syntax is primarily focused on creating which of the following?

a)

Code blocks

b)

Functions

c)

Objects

d)

None of these options

2.

The following syntax is used when creating a class:


class def Fruit

a)

True

b)

False

3.

The following syntax is used to initialize objects:


class Teams (object)

def __init__(self):

a)

True

b)

False

4.

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

a)

New_York

b)

Mets

c)

New_York = Mets

d)

New York = "Mets"

5.

Variables that may be used throughout the code block are labeled...

a)

Global Variables

b)

Member Variables

c)

Instance Variables

d)

Dependent Variables

6.

The scope of a variable is the context in which it's visible to the program.

a)

True

b)

False

7.

When a class has its own functions, those functions are called...

a)

Member Variables

b)

Global Variables

c)

Methods

d)

None of these options

8.

The process by which one class takes on the attributes and methods of another is called...

a)

Inheritance

b)

Global Variables

c)

__init__

d)

None of these options

9.

When creating classes, there are both parent and derived classes.

a)

True

b)

False

10.

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

a)

Employee

b)

Hours

c)

PartTimeEmployee

d)

None of these options

11.

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()

a)

2, True

b)

4, False

c)

3, False

d)

3, True

12.

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

a)

True

b)

False

13.

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)

a)

200.0

b)

250.0

c)

100.0

d)

85.0

14.

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

a)

True

b)

False

15.

Which of the following variables is available to all parts of the class?

a)

Global

b)

Instance

c)

Local

d)

Member

16.

In the following code block, which of the following lines utilize dot notation?


class Square(object):

def __init__(self):

self.sides = 4

a)

class Square(object)

b)

def __init__(self)

c)

self.sides = 4

d)

None of these options