Question

DI Question 2 1.5 pts Which situations allow the client main() in the file my_program.py to access a method name, say func(),D Question 3 1.5 pts In which type of instance methods is it typically necessary to filter bad arguments (either directly orDI Question 4 1.5 pts A binary search algorithm is written (as in the modules, for example) which searches a pre-sorted arrayD Question 5 1.5 pts Consider the following code fragment (assumed to be in an otherwise correct program) class MyClass: sharDI Question 6 1.5 pts Check the true statements about error handling in Python: O type(x)MyType will be False if x is an inst

DI Question 2 1.5 pts Which situations allow the client main() in the file my_program.py to access a method name, say func(), alone, as in x-func) without dereferencing it using prepended name like modname.func or x = some object. func () or x-SomeClass.func() O func) is defined in some module, say, "modname.py" and modname is imported into my_program.py using: from modname import func() is an instance method or a class method in a class, say SomeClass, defined in the same file my program.py, as client, main) O func() is defined in some module, say."modname.py" and modname is imported into my_program.py using: import modname func) is a global scope function defined in the same file my program.py, as client, mainO.
D Question 3 1.5 pts In which type of instance methods is it typically necessary to filter bad arguments (either directly or indirectly with the help of validators or mutators) in order to protect private data of your class? A display) (or show()) method, which takes no parameters (other than the self parameter), intended to output the data of the class for the display. A constructor that takes parameters (above and beyond the self parameter). A mutator that takes no parameters (other than the self parameter) from the client, like a reset) or clear), intended to zero-out or assign default values to instance data based on a predetermined behavior. A to_string) or_str_() method, which takes no parameters (other than the self parameter), intended to return some data to the client in the form of a string. A set) method (non-constructor mutator) that takes parameters (above and beyond the self parameter) A get0 method (non-constructor accessor) which takes no parameters (other than the self parameter).
DI Question 4 1.5 pts A binary search algorithm is written (as in the modules, for example) which searches a pre-sorted array for some user-defined value, client data. If client data is stored in the array, it returns its array position, and if not found, it returns-1 (again, just like in the modules). Assume the array to be searched has 100 data elements in it. (Check all that apply) NOTE: due to common off-by-one interpretations when counting such things, if your predicted answer is within one (+1 or -1) of a posted option below, you can assume your prediction and the choice you are looking at are equivalent and check that option.] Each recursive call throws away half of the elements it gets. The method gets 100 elements, but if client data is not found in position 49 (first comparison) the method throws 51 of those elements away and calls itself. This inner call now has 49 elements to search. It tests element 24 against client data (second comparison), and if it is not a match, throws away about half again, leaving 24. The next call/comparison, if needed throws away about 12. The next call, if needed, throws away 6. The next call throws away 3. The next call throws away 2. Finally we only have one element to test Each recursive call does one comparison. How many comparisons have we done, give or take one, (count above) in the worst case, assuming we have to go all the way down until we only have one element before we find the data we are searching for? It will always return with an answer in 7 or fewer comparisons of data. It will always return with an answer in 3 or fewer comparisons of data. It may require as many as 99 comparisons of data before it returns. It might return to the client with an answer after only one comparison of data.
D Question 5 1.5 pts Consider the following code fragment (assumed to be in an otherwise correct program) class MyClass: shared max -200 def get _max(self): return self.shared_max def set_max(self, new_max): self.shared max new max Assume there are no omitted statements within this fragment you see everything. Check the true statements (may be more than one): The accessor, when invoked, might, in certain situations, cause its self.shared_max to refer to an instance attribute O Both methods, when invoked, will always cause their self.shared max to refer to the static attribute O The mutator, when invoked, will always cause its self.shared_max to refer to an instance attribute. O Both methods, when invoked, will always cause their self.shared_max to refer to an instance attribute. The accessor, when invoked, will always cause its self.shared_max to refer to the static attribute.
DI Question 6 1.5 pts Check the true statements about error handling in Python: O type(x)MyType will be False if x is an instance of a proper subclass of MyType. You need a separate trylcatch block for each kind of error you are screening. One try block can be used to handle many different types of errors raised by Python, but will jump to the except block at the first infraction detected (skipping any potential problems in the remainder/below the infraction detected) Range testing ("is x between a and b?" kinds of questions) is best handled using try/except blocks. isinstance(x, MyType) will be False if x is an instance of a proper subclass of MyType.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

2. B

func ( ) is an instance method or a class method in a class, say, some class defined in the same file my_program.py,as client,main ( ).

3.C

A mutator that takes no parameters other than the self parameter from the client like reset ( ), or clear ( ). that is intended to zero -out or that can assign the default values to the instant database on the predetermined behavior.

4.D

It might return the client with an answer after only one comparison of the data.

5. A

The accessor, When Invoked, Might, in certain situations, cause itself shared_max to refer to an attribute.

6.C

One try block can be used to handle many different types of errors raised in the python, but they will jump to the except block at the first infraction detected.

That means skipping of any potential problems in the reminder/ below the infraction that is detected.

Add a comment
Know the answer?
Add Answer to:
DI Question 2 1.5 pts Which situations allow the client main() in the file my_program.py to access a method name, say f...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • IN PYTHON Assignment Overview This assignment will give you experience on the use of classes. Understand...

    IN PYTHON Assignment Overview This assignment will give you experience on the use of classes. Understand the Application The assignment is to first create a class calledTripleString.TripleStringwill consist of threeinstance attribute strings as its basic data. It will also contain a few instance methods to support that data. Once defined, we will use it to instantiate TripleString objects that can be used in our main program. TripleString will contain three member strings as its main data: string1, string2, and string3....

  • Overview This assignment will give you experience on the use of classes. Understand the Application Every...

    Overview This assignment will give you experience on the use of classes. Understand the Application Every internet user–perhaps better thought of as an Internet connection–has certain data associated with him/her/it. We will oversimplify this by symbolizing such data with only two fields: a name ("Aristotle") and a globally accessible IP address ("139.12.85.191"). We could enhance these by adding other—sometimes optional, sometimes needed—data (such as a MAC address, port, local IP address, gateway, etc), but we keep things simple and use...

  • Program Purpose In this program you will demonstrate your knowledge in programming OOP concepts, such as classes, encapsulation, and procedural programming concepts such as lınked lists, dynamic me...

    Program Purpose In this program you will demonstrate your knowledge in programming OOP concepts, such as classes, encapsulation, and procedural programming concepts such as lınked lists, dynamic memory allocation, pointers, recursion, and debugging Mandatory Instructions Develop a C++ object oriented solution to the Towers of Hanoi puzzle. Your solution will involve designing two classes one to represent individual Disk and another to represent the TowersOfHanoi game. TowersOfHanoi class will implement the game with three linked lists representing disks on each...

  • In a new file located in the same package as the class Main, create a public...

    In a new file located in the same package as the class Main, create a public Java class to represent a photograph that consists of a linear (not 2D) array of pixels. Each pixel is stored as an integer. The photograph class must have: (a) Two private fields to represent the information stored about the photograph. These are the array of integers and the date the photograph was taken (stored as a String). The values in the array must be...

  • Programming Project #5 Project Outcomes: Develop a Java program that Uses selection constructs (if, and if...

    Programming Project #5 Project Outcomes: Develop a Java program that Uses selection constructs (if, and if else). Uses the Java iteration constructs (while, do, for). Uses static variables. Ensure integer variables input are within a range that will not cause integer overflow. Uses proper design techniques including reading UML Class Diagrams Background Information: The Unified Modeling Language (UML) provides a useful notation for designing and developing object-oriented software systems. One of the basic components of the UML is a class...

  • What is the role of polymorphism? Question options: Polymorphism allows a programmer to manipulate objects that...

    What is the role of polymorphism? Question options: Polymorphism allows a programmer to manipulate objects that share a set of tasks, even though the tasks are executed in different ways. Polymorphism allows a programmer to use a subclass object in place of a superclass object. Polymorphism allows a subclass to override a superclass method by providing a completely new implementation. Polymorphism allows a subclass to extend a superclass method by performing the superclass task plus some additional work. Assume that...

  • Activity: Writing Classes Page 1 of 10 Terminology attribute / state behavior class method header class...

    Activity: Writing Classes Page 1 of 10 Terminology attribute / state behavior class method header class header instance variable UML class diagram encapsulation client visibility (or access) modifier accessor method mutator method calling method method declaration method invocation return statement parameters constructor Goals By the end of this activity you should be able to do the following: > Create a class with methods that accept parameters and return a value Understand the constructor and the toString method of a class...

  • please use python and provide run result, thank you! click on pic to make it bigger...

    please use python and provide run result, thank you! click on pic to make it bigger For this assignment you will have to investigate the use of the Python random library's random generator function, random.randrange(stop), randrange produces a random integer in the range of 0 to stop-1. You will need to import random at the top of your program. You can find this in the text or using the online resources given in the lectures A Slot Machine Simulation Understand...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT