A201 Introduction to Programming 1

A201 Homework 13

Due Date: Tuesday, December 5, 2023.

Goal: to define a class in Python.

Make sure to complete Lab 13 before doing the homework.

Create a Python script file called hw13.py. Add your name at the top as a comment, along with the class name and date.

Ex. 1. Classes and Objects

a. Declare a class called Book that represents a book. In the constructor__init__, use the parameter self and 3 more parameters representing the title, the author, and the publication year. Store the values of these parameters in class attributes. Generate a random value between 10000 and 99999 and store it in an attribute called isbn.

b. Add a class method called display(self) that prints out the information in the object. Add a function main where you create a couple of objects of the class Book and call the function display from each of them.

c. Write another method called isSequel(self, other) that checks if the calling book (the object self) is a sequel of the book other. For that, the two books must have the same author and the publication year of the calling book must be later than that of the second book. The function should return true if both of these conditions are true, and false if not.

Add a call to this function in the main using the two book objects you declared and print the result.

Homework Submission

Upload the files lab13.py, Car.py and hw13.py in Canvas, Assignments, Homework 13.