You are on page 1of 18

Test Bank for Fundamentals of Python: Data Structures 2nd Edition Kenneth Lambert

Test Bank for Fundamentals of Python: Data


Structures 2nd Edition Kenneth Lambert

To download the complete and accurate content document, go to:


https://testbankbell.com/download/test-bank-for-fundamentals-of-python-data-structur
es-2nd-edition-kenneth-lambert/

Visit TestBankBell.com to get complete for all chapters


Name: Class: Date:

Chapter 06: Inheritance and Abstract Classes


1. The easiest way to take advantage of inheritance is to use it to customize an existing class.
a. True
b. False
ANSWER: True
POINTS: 1
DIFFICULTY: Easy
REFERENCES: Using Inheritance to Customize an Existing Class
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM

2. When a class is customized using inheritance, the two classes should have a similar interface.
a. True
b. False
ANSWER: True
POINTS: 1
DIFFICULTY: Easy
REFERENCES: Using Inheritance to Customize an Existing Class
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM

3. When you use inheritance to customize a class, the existing and new class have identical behavior.
a. True
b. False
ANSWER: False
POINTS: 1
DIFFICULTY: Easy
REFERENCES: Using Inheritance to Customize an Existing Class
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM

4. A class that inherits properties from another class is called a superclass.


a. True
b. False
ANSWER: False
POINTS: 1
DIFFICULTY: Easy
Copyright Cengage Learning. Powered by Cognero. Page 1
Name: Class: Date:

Chapter 06: Inheritance and Abstract Classes


REFERENCES: Using Inheritance to Customize an Existing Class
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM

5. To begin creating a subclass, copy the parent class's file and delete the methods that will not change.
a. True
b. False
ANSWER: True
POINTS: 1
DIFFICULTY: Easy
REFERENCES: Using Inheritance to Customize an Existing Class
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM

6. To ensure that inheritance occurs, you need to place the name of the subclass in parentheses of the class
header.
a. True
b. False
ANSWER: False
POINTS: 1
DIFFICULTY: Moderate
REFERENCES: Using Inheritance to Customize an Existing Class
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM

7. The __init__ method in the parent class is automatically called by a subclass of the parent class.
a. True
b. False
ANSWER: False
POINTS: 1
DIFFICULTY: Moderate
REFERENCES: Using Inheritance to Customize an Existing Class
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM
Copyright Cengage Learning. Powered by Cognero. Page 2
Name: Class: Date:

Chapter 06: Inheritance and Abstract Classes

8. When calling the __init__ method from a subclass, you need to include the self argument.
a. True
b. False
ANSWER: True
POINTS: 1
DIFFICULTY: Easy
REFERENCES: Using Inheritance to Customize an Existing Class
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM

9. To distinguish a method in the parent class from a method with the same name in a subclass, prefix the
method name with self.
a. True
b. False
ANSWER: False
POINTS: 1
DIFFICULTY: Easy
REFERENCES: Using Inheritance to Customize an Existing Class
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM

10. The root class of the Python hierarchy is called object.


a. True
b. False
ANSWER: True
POINTS: 1
DIFFICULTY: Easy
REFERENCES: Using Inheritance to Customize an Existing Class
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM

11. By using inheritance to create new classes, you increase code redundancy.
a. True
b. False
ANSWER: False
Copyright Cengage Learning. Powered by Cognero. Page 3
Name: Class: Date:

Chapter 06: Inheritance and Abstract Classes


POINTS: 1
DIFFICULTY: Easy
REFERENCES: Using Abstract Classes to Eliminate Redundant Code
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM

12. An abstract class captures the common features and behavior of a set of related classes.
a. True
b. False
ANSWER: True
POINTS: 1
DIFFICULTY: Easy
REFERENCES: Using Abstract Classes to Eliminate Redundant Code
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM

13. An abstract class is always used to create objects in client applications.


a. True
b. False
ANSWER: False
POINTS: 1
DIFFICULTY: Easy
REFERENCES: Using Abstract Classes to Eliminate Redundant Code
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM

14. A concrete class is often a subclass of an abstract class and is used to create objects in client applications.
a. True
b. False
ANSWER: True
POINTS: 1
DIFFICULTY: Easy
REFERENCES: Using Abstract Classes to Eliminate Redundant Code
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
Copyright Cengage Learning. Powered by Cognero. Page 4
Name: Class: Date:

Chapter 06: Inheritance and Abstract Classes


DATE MODIFIED: 9/2/2018 6:19 PM

15. An instance variable is considered redundant if two different classes use it and it refers to a different type of
data structure in each class.
a. True
b. False
ANSWER: False
POINTS: 1
DIFFICULTY: Easy
REFERENCES: Using Abstract Classes to Eliminate Redundant Code
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM

16. An instance variable that refers to an integer in two different related classes is a likely candidate to be
moved to an abstract class.
a. True
b. False
ANSWER: True
POINTS: 1
DIFFICULTY: Easy
REFERENCES: Using Abstract Classes to Eliminate Redundant Code
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM

17. A set of methods that could be used on other data structures besides the one they were created for could be
used in a general abstract class.
a. True
b. False
ANSWER: True
POINTS: 1
DIFFICULTY: Moderate
REFERENCES: An Abstract Class for All Collections
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM

18. When looking at a hierarchy of abstract classes, the classes trend from the more specific to the more general
going from the top to the bottom of the hierarchy.
Copyright Cengage Learning. Powered by Cognero. Page 5
Name: Class: Date:

Chapter 06: Inheritance and Abstract Classes


a. True
b. False
ANSWER: False
POINTS: 1
DIFFICULTY: Moderate
REFERENCES: An Abstract Class for All Collections
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM

19. The implementations of the __str__ and __eq__ methods in the AbstractCollection class can be used in both
unordered and linear collections.
a. True
b. False
ANSWER: False
POINTS: 1
DIFFICULTY: Moderate
REFERENCES: An Abstract Class for All Collections
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM

20. A class that uses lists can use the methods defined in the AbstractCollection class.
a. True
b. False
ANSWER: True
POINTS: 1
DIFFICULTY: Easy
REFERENCES: An Abstract Class for All Collections
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM

21. The __eq__ method in the AbstractCollection class compares pairs of items in two collections.
a. True
b. False
ANSWER: True
POINTS: 1
DIFFICULTY: Easy
Copyright Cengage Learning. Powered by Cognero. Page 6
Name: Class: Date:

Chapter 06: Inheritance and Abstract Classes


REFERENCES: An Abstract Class for All Collections
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM

22. A primary purpose of using inheritance is to eliminate redundant code.


a. True
b. False
ANSWER: True
POINTS: 1
DIFFICULTY: Easy
REFERENCES: A Professional-Quality Framework of Collections
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM

23. Programming languages such as Java include a collection framework more extensive than that of Python.
a. True
b. False
ANSWER: True
POINTS: 1
DIFFICULTY: Easy
REFERENCES: A Professional-Quality Framework of Collections
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM

24. When a programmer calls the iter function on a collection, the collection's iterator object is returned.
a. True
b. False
ANSWER: True
POINTS: 1
DIFFICULTY: Easy
REFERENCES: An Abstract Class for All Collections
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:20 PM

Copyright Cengage Learning. Powered by Cognero. Page 7


Name: Class: Date:

Chapter 06: Inheritance and Abstract Classes


25. If a programmer calls the next function on an iterator object and there is no current item in the sequence, the
next function returns the Null item.
a. True
b. False
ANSWER: False
POINTS: 1
DIFFICULTY: Moderate
REFERENCES: Abstract Class for All Collections
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM

26. What is one of the primary purposes of using inheritance?


a. to customize an existing class
b. to create code redundancy
c. to avoid creating an __init__ method
d. to duplicate methods in an interface
ANSWER: a
POINTS: 1
DIFFICULTY: Easy
REFERENCES: Using Inheritance to Customize an Existing Class
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM

27. Which of the following is true about the sorted bag collection compared to the regular bag collection?
a. the add method is identical in both
b. the __init__ method is identical in both
c. the sorted bag's in operator runs in linear time
d. the items in a sorted bag must be of the same type
ANSWER: d
POINTS: 1
DIFFICULTY: Moderate
REFERENCES: Using Inheritance to Customize an Existing Class
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM

28. When considering the ArrayBag class and the ArraySortedBag class, which of the following is true?
Copyright Cengage Learning. Powered by Cognero. Page 8
Name: Class: Date:

Chapter 06: Inheritance and Abstract Classes


a. the ArraySortedBag class is the parent of the ArrayBag class
b. the ArraySortedBag class is a subclass of ArrayBag
c. the ArrayBag class is a subclass of ArraySortedBag
d. the ArrayBag class is the child class of ArraySortedBag
ANSWER: b
POINTS: 1
DIFFICULTY: Moderate
REFERENCES: Using Inheritance to Customize an Existing Class
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM

29. How is creating a subclass of an existing class different from copying the code from the existing class to a
new file?
a. delete all the methods that don't have to change
b. you don't need an __init__ method
c. the name of the subclass is in parentheses of the class header
d. no methods need be created or modified
ANSWER: a
POINTS: 1
DIFFICULTY: Easy
REFERENCES: Using Inheritance to Customize an Existing Class
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM

30. Which of the following is NOT a step in using inheritance to create a subclass?
a. delete the methods that do not change
b. duplicate redundant instance variables
c. modify the code for methods that change
d. add any new methods
ANSWER: b
POINTS: 1
DIFFICULTY: Easy
REFERENCES: Using Inheritance to Customize an Existing Class
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM
Copyright Cengage Learning. Powered by Cognero. Page 9
Name: Class: Date:

Chapter 06: Inheritance and Abstract Classes


31. What is the syntax for the calling the __init__ method in the ArrayBag class from the ArraySortedBag
class?
a. self.init(ArrayBag, sourceCollection)
b. ArrayBag.self(__init__, sourceCollection)
c. ArrayBag.__init__(self, sourceCollection)
d. __init__.ArrayBag(self, sourceCollection)
ANSWER: c
POINTS: 1
DIFFICULTY: Moderate
REFERENCES: Using Inheritance to Customize an Existing Class
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM

32. In the ArraySortedBag class, why must the self argument be passed to the __init__ method of ArrayBag?
a. to ensure the add method in ArraySortedBag is called if a source collection is specified
b. to ensure that ArraySortedBag calls the correct __init__ method
c. to ensure that ArrayBag calls its own __init__ method
d. to ensure the add method in ArrayBag is called if a source collection is specified
ANSWER: a
POINTS: 1
DIFFICULTY: Difficult
REFERENCES: Using Inheritance to Customize an Existing Class
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM

33. What method is called when the in operator is used on a sorted bag?
a. __iter__
b. __contains__
c. __init__
d. add
ANSWER: b
POINTS: 1
DIFFICULTY: Moderate
REFERENCES: Using Inheritance to Customize an Existing Class
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM

Copyright Cengage Learning. Powered by Cognero. Page 10


Name: Class: Date:

Chapter 06: Inheritance and Abstract Classes


DATE MODIFIED: 9/2/2018 6:19 PM

34. In which situation is a search unnecessary when performing the add method on a sorted bag?
a. when the bag is full
b. when the new item is less than the last item
c. when the new item is greater than the first item
d. when the bag is empty
ANSWER: d
POINTS: 1
DIFFICULTY: Moderate
REFERENCES: Using Inheritance to Customize an Existing Class
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM

35. The following code is part of the add method in the ArraySortedBag class. What is the missing code?

if self.isEmpty() or item >= self.items[len(self) - 1]:


<missing code>

a. add.self(item)
b. ArrayBag.add(item)
c. ArrayBag.add(self, item)
d. add.ArrayBag(self, item)
ANSWER: c
POINTS: 1
DIFFICULTY: Difficult
REFERENCES: Using Inheritance to Customize an Existing Class
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM

36. Which operator, when used with two bags, causes Python to run the __add__ method?
a. =
b. *
c. +
d. %
ANSWER: c
POINTS: 1
DIFFICULTY: Easy
Copyright Cengage Learning. Powered by Cognero. Page 11
Name: Class: Date:

Chapter 06: Inheritance and Abstract Classes


REFERENCES: Using Inheritance to Customize an Existing Class
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM

37. What is the root class of Python's built-in class hierarchy?


a. self
b. list
c. dict
d. object
ANSWER: d
POINTS: 1
DIFFICULTY: Easy
REFERENCES: Using Inheritance to Customize an Existing Class
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM

38. What is a class called when the purpose of it is to eliminate redundant methods in other classes?
a. concrete class
b. abstract class
c. subclass
d. child class
ANSWER: b
POINTS: 1
DIFFICULTY: Easy
REFERENCES: Using Abstract Classes to Eliminate Redundant Code
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM

39. Which of the following is true about abstract classes?


a. they are the same as a class interface
b. the are always a subclass of a superclass
c. they are not normally instantiated in client applications
d. they are used as concrete classes by client applications
ANSWER: c
POINTS: 1

Copyright Cengage Learning. Powered by Cognero. Page 12


Name: Class: Date:

Chapter 06: Inheritance and Abstract Classes


DIFFICULTY: Easy
REFERENCES: Using Abstract Classes to Eliminate Redundant Code
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM

40. Under which circumstance can an instance variable be moved to an abstract class?
a. when it refers to the same type of data structure
b. when it is unique to a particular concrete class
c. when different data structure types are referenced by the variable
d. when it directly modifies the underlying data structure
ANSWER: a
POINTS: 1
DIFFICULTY: Moderate
REFERENCES: Using Abstract Classes to Eliminate Redundant Code
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM

41. Which of the following is true about the three bag classes (LinkedBag, ArrayBag, ArraySortedBag)?
a. they are abstract classes
b. they implement the bag interface
c. the are all superclasses
d. LinkedBag is a subclass of ArraySortedBag
ANSWER: b
POINTS: 1
DIFFICULTY: Easy
REFERENCES: Using Abstract Classes to Eliminate Redundant Code
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM

42. When implementing the __init__ method in the AbstractBag class, what task should you leave out because
it is the responsibility of the subclasses?
a. setting the self.size variable to 0
b. adding items from the source collection
c. initializing the self.items variable
d. checking if a source collection exists

Copyright Cengage Learning. Powered by Cognero. Page 13


Name: Class: Date:

Chapter 06: Inheritance and Abstract Classes


ANSWER: c
POINTS: 1
DIFFICULTY: Moderate
REFERENCES: Using Abstract Classes to Eliminate Redundant Code
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM

43. When you finish writing the abstract class, what must the subclasses do to use it?
a. reference the abstract class in their __init__ method.
b. copy the code to the subclass file
c. nothing, the abstract class is automatically included in the subclass
d. import the abstract class
ANSWER: d
POINTS: 1
DIFFICULTY: Moderate
REFERENCES: Using Abstract Classes to Eliminate Redundant Code
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM

44. In the constructor for the ArrayBag class shown below, what is the missing code?

def __init__(self, sourceCollection = None):


<missing code>
AbstractBag.__init__(self, sourceCollection)

a. items.add(self)
b. self.items = Array(ArrayBag.DEFAULT_CAPACITY)
c. self.items = ArrayBag.add(sourceCollection)
d. add.items(self, sourceCollection)
ANSWER: b
POINTS: 1
DIFFICULTY: Difficult
REFERENCES: Using Abstract Classes to Eliminate Redundant Code
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM

Copyright Cengage Learning. Powered by Cognero. Page 14


Name: Class: Date:

Chapter 06: Inheritance and Abstract Classes


45. What would be the purpose of creating a more general abstract class called AbstractCollection?
a. to group methods used by a single subclass
b. to hide the details of the methods used in your abstract classes
c. to create objects from a client application
d. to group methods that can be used for other types of collections
ANSWER: d
POINTS: 1
DIFFICULTY: Moderate
REFERENCES: An Abstract Class for All Collections
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM

46. In the case of the AbstractCollection class, which of the following methods should NOT be included in this
class?
a. add
b. isEmpty
c. __len__
d. count
ANSWER: a
POINTS: 1
DIFFICULTY: Moderate
REFERENCES: An Abstract Class for All Collections
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM

47. When creating the AbstractCollection class, which methods must you modify to provide default behavior?
a. __len__ and count
b. __str__ and __eq__
c. isEmpty and add
d. __init__ and __len__
ANSWER: b
POINTS: 1
DIFFICULTY: Difficult
REFERENCES: An Abstract Class for All Collections
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM

Copyright Cengage Learning. Powered by Cognero. Page 15


Name: Class: Date:

Chapter 06: Inheritance and Abstract Classes


DATE MODIFIED: 9/2/2018 6:19 PM

48. When a programmer calls the next function on an iterator object, what happens if there is no current item in
the sequence?
a. the previous item is returned
b. the compiler generates an error
c. a StopIteration exception is raised
d. the None item is returned
ANSWER: c
POINTS: 1
DIFFICULTY: Easy
REFERENCES: An Abstract Class for All Collections
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM

49. In the following code for the ArrayBag class __contains__ method, what is the missing code?

def __contains__(self, item):


left = 0
right = len(self) - 1
while left <= right:
midPoint = (left + right) // 2
if self.items[midPoint] == item:
return True
elif self.items[midPoint] > item:
right = midPoint - 1
else:
<missing code>
return False

a. right = midPoint + 1
b. left = midPoint - 1
c. right = left + 1
d. left = midPoint + 1
ANSWER: d
POINTS: 1
DIFFICULTY: Difficult
REFERENCES: Using Inheritance to Customize an Existing Class
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM
Copyright Cengage Learning. Powered by Cognero. Page 16
Test Bank for Fundamentals of Python: Data Structures 2nd Edition Kenneth Lambert

Name: Class: Date:

Chapter 06: Inheritance and Abstract Classes

50. In the following code for the __add__ method in the ArraySortedBag class, what is the missing code?

def __add__(self, other):


result = ArraySortedBag(self)
for item in other:
<missing code>
return result

a. result = result + 1
b. item.add(result)
c. result.add(item)
d. add.item(result)
ANSWER: c
POINTS: 1
DIFFICULTY: Difficult
REFERENCES: Using Inheritance to Customize an Existing Class
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM

Copyright Cengage Learning. Powered by Cognero. Page 17

Visit TestBankBell.com to get complete for all chapters

You might also like