Filters
Question type

Study Flashcards

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

E) A) and D)
F) B) and C)

Correct Answer

verifed

verified

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

Correct Answer

verifed

verified

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

E) None of the above
F) B) and C)

Correct Answer

verifed

verified

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)

E) A) and C)
F) All of the above

Correct Answer

verifed

verified

To ensure that inheritance occurs, you need to place the name of the subclass in parentheses of the class header.

A) True
B) False

Correct Answer

verifed

verified

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)

E) All of the above
F) A) and B)

Correct Answer

verifed

verified

C

Programming languages such as Java include a collection framework more extensive than that of Python.

A) True
B) False

Correct Answer

verifed

verified

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

Correct Answer

verifed

verified

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

E) None of the above
F) All of the above

Correct Answer

verifed

verified

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

E) A) and B)
F) C) and D)

Correct Answer

verifed

verified

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

Correct Answer

verifed

verified

When a programmer calls the iter function on a collection, the collection's iterator object is returned.

A) True
B) False

Correct Answer

verifed

verified

When a class is customized using inheritance, the two classes should have a similar interface.

A) True
B) False

Correct Answer

verifed

verified

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

E) A) and D)
F) C) and D)

Correct Answer

verifed

verified

To begin creating a subclass, copy the parent class's file and delete the methods that will not change.

A) True
B) False

Correct Answer

verifed

verified

The __eq__ method in the AbstractCollection class compares pairs of items in two collections.

A) True
B) False

Correct Answer

verifed

verified

Which operator, when used with two bags, causes Python to run the __add__ method?


A) =
B) *
C) +
D) %

E) B) and D)
F) All of the above

Correct Answer

verifed

verified

C

A concrete class is often a subclass of an abstract class and is used to create objects in client applications.

A) True
B) False

Correct Answer

verifed

verified

True

The easiest way to take advantage of inheritance is to use it to customize an existing class.

A) True
B) False

Correct Answer

verifed

verified

What method is called when the in operator is used on a sorted bag?


A) __iter__
B) __contains__
C) __init__
D) add

E) None of the above
F) B) and C)

Correct Answer

verifed

verified

Showing 1 - 20 of 50

Related Exams

Show Answer