Instructor solution
Object-Oriented Programming (OOP) in Python presentation (pages 8-10)
You may exit out of this review and return later without penalty.
Object-Oriented Programming (OOP) in Python Assignment
1.Dunder Methods: Modify the DunderObj class to make len(obj) return the product of two constructor parameters a and b, where obj is an instance of DunderObj and a and b are ints.
2.Dunder Methods: Modify the DunderObj class to make str(obj) return "a is larger than b", "b is larger than a", or "a and b are equal", depending on the values of two constructor parameters a and b.
3.Dunder Methods: Add a constructor to the PersonObj class to make str(obj) return if a person will be able to afford their rent.
4.What is a dunder method?
5.Dunder methods: Write a class DunderObj with a constructor that takes in a string name and considers objects to be equal if their name attribute is equal.
6.Generators: Write a generator function that yields all numbers up to a parameter test_num that are divisible by a parameters divisor.
7.What is a generator function in Python?
8.Give an example of when you might want to use a generator function in Python.
9.Write a function that uses a generator to return the \(n^{th}\) prime number.
10.Generators: Write a generator function in Python that iterates through lines in a plain text file.
11.Inheritance: Write a class Cat that inherits from Pet, with some differences described below.
12.Inheritance: Write a class Rectangle that inherits from Shape, with some differences described below.
13.What is multiple inheritance and when may you want to use it in Python?
14.What is the result of the code in Figure A?
15.Multilevel Inheritance Write a class that inherits from one base class that inherits from another base class, as described below.
You may exit out of this review and return later without penalty.