Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me with the following 9 Python 3.8 multiple choices and short answer questions. Thank you very much! Question 1 1 pts A library

Please help me with the following 9 Python 3.8 multiple choices and short answer questions. Thank you very much!

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Question 1 1 pts A library contains books and DVDS, which can be checked out and returned. A warning is sent to borrowers who have overdue items. Books can be renewed but DVDS cannot, and DVDS have a shorter loan period than books. The library may expand in future to include other kinds of items. Suppose you are designing classes for the library. Which of the designs below is most appropriate? A Libraryltem parent class that stores common information such as due date, and child classes Book and DVD. O A Libraryltem class whose attributes can be initialized differently depending on whether it represents a book or DVD O A Book class and a DVD class that are unrelated, and a Libraryltem class that stores an instance of Book or DVD in an instance attribute A Book class and a DVD class that have no relationship Question 2 1 pts Suppose we have a Parent class that has a method that is not completed because child classes have different implementations. Fill in the blank in the code below. class Parent: # docstring, -_init__ omitted def method(self) -> None: """A method that differs for each of the child classes. raise Question 3 1 pts Which of the following is true about abstract classes? Abstract classes should never be instantiated An abstract class can be instantiated if it is likely that the abstract methods will never be called Abstract classes should only be instantiated when a more specific subclass does not exist It is acceptable to instantiate an abstract class in any situation Question 4 1 pts Given the code below, which of the following statements could go in the main block and would execute without raising an error? class Mystery: """A mystery class without any implementation. pass if name. '_main_': Mystery('what is this?') Mystery() Mystery() print(m) None of the above. They would all raise an error. Question 5 1 pts What would be the result of running the code below? class Parent: """An arbitrary class num1: int def _init_(self, num1: int) -> None: self.num1 num1 %3D class Child(Parent): """A subclass. num2: int def _init_(self, num1: int, num2: int) -> None: self.num2 num2 %3D if name__ '_main_': Child(1, 2) print(c.num2) print(c.num1) Traceback (most recent call last): AttributeError 2. Traceback (most recent call last): ... AttributeError 1 pts Question 6 An animal has attributes such as species and age. A mammal is a kind of animal that has additional attributes such as the colour of its fur (all mammals have fur/hair). We have started some code for an Animal class and a Mammal subclass, and now we want to implement initializers. Which code is the most appropriate? class Animal: """DOCSTRING OMITTED""" def init_(self, species: str, age: int) -> None: """Initialize this Animal. Precondition: age >= 0 self.species self.age species age %3D class Mammal (Animal): ""DOCSTRING OMITTED"' def _init_(self, species: str, age: int, fur_colour: str) -> None: """Initialize this Mammal. self.species self.age species %3D age self.fur_colour fur_colour class Animal: """DOCSTRING OMITTED""" def _init_(self, species: str, age: int) -> None: """Initialize this Animal. Precondition: age >= 0 self.species self.age species %3D = age class Mammal (Animal): "DOCSTRING OMITTED""" def _init_(self, species: str, age: int, fur_colour: str) -> None: "Initialize this Mammal. Animal._init__(self) self.fur_colour fur_colour class Animal: """DOCSTRING OMITTED""" def _init_(self, species: str, age: int) -> None: """Initialize this Animal. Precondition: age >= 0 self.species self.age species = age class Mammal (Animal): "DOCSTRING OMITTED""" def _init_(self, species: str, age: int, fur_colour: str) -> None: """Initialize this Mammal. Animal._init__(self, species, age) self.species self.age species age %3D self.fur_colour fur_colour class Animal: ""DOCSTRING OMITTED" def _init_(self, species: str, age: int) -> None: """Initialize this Animal. Precondition: age >= 0 self.species = species self.age age class Mammal (Animal): """DOCSTRING OMITTED""" def init_(self, species: str, age: int, fur_colour: str) -> None: """Initialize this Mammal. Animal._init__(self, species, age) self.fur_colour fur_colour Question 7 1 pts What will be the output of the three calls to print_message at the end of this program? class Printer: *"A Printer. Attributes === message: the message to print message: str def _init_(self, message: str) -> None: self.message = message def print_message(self): "*"Prints a message. print(self.message) class MysteryPrinter(Printer): def _init_(self, message: str) -> None: Printer._init_(self, message + message) class DoublePrinter(MysteryPrinter): def print_message(self): print(self.message + self.message) = '-_main_': if name ml = Printer('hello') m2 = MysteryPrinter('good') m3 = DoublePrinter('bye') ml.print_message() m2.print_message() m3.print_message() Line 1: Line 2: Line 3: Question 8 1 pts Given the code below, which of the following statements will evaluate to True? class F: # Implementation Omitted class G(F): # Implementation Omitted class H(F): # Implementation Omitted if name_ f = F() g = GC) ) '_main_': %3D type(f) == type(g) isinstance(g, H) isinstance(g, F) isinstance(h, F) isinstance(h, G) type(g) == type(h) 1 pts Question 9 Given the code below, which of the following statements will evaluate to True? class Machine: # implementation omitted class Calculator(Machine): # implementation omitted class FourFunctionCalculator(Calculator): # implementation omitted if == '_main_': -name Machine() Calculator() f = FourFunctionCalculator() type(f) == type(c) type(m) == type(f) isinstance(m, Calculator) isinstance(f, Calculator) isinstance(f, Machine) isinstance(c, Machine) type(m) == type(c)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Visual Basic6 Database Programming

Authors: John W. Fronckowiak, David J. Helda

1st Edition

0764532545, 978-0764532542

More Books

Students also viewed these Databases questions