Class Interaction in Python: Author and Book Classes
Level: Beginner
Your task for today is to build two related classes — one for an author and one for a book. This project introduces you to how objects can interact with each other, and how to model real-world relationships in Python using OOP.
📝 Project Task
The program should:
Define a class
Authorwith attributes:name(string)birth_year(integer)
Define a class
Bookwith attributes:title(string)year(integer)author(anAuthorobject)
Add the following methods:
Book.get_info()→ returns a string like"Book Title by Author Name"Author.write_book(title, year)→ returns a newBookinstance associated with that author
Bonus (optional):
Let the author store all books they’ve written
Add
__str__()methods for nicer printingAdd a method
Author.get_bibliography()that prints all titles by the author
This project teaches you how to:
Build multiple classes that reference each other
Create object relationships
Model simple real-world systems like authors and their books
📌 Expected Output
a = Author("George Orwell", 1903)
b = a.write_book("1984", 1949)
print(b.get_info()) # 1984 by George Orwell
print(b.author.name) # George Orwell
💻 Launch This Project in Colab
Open the interactive Google Colab notebook for today’s project — with full instructions, hints, and solutions.
Click the button below to start coding — no setup needed:
Keep reading with a 7-day free trial
Subscribe to Daily Python Projects to keep reading this post and get 7 days of free access to the full post archives.


