A Book That Prints Nicely
Python
15 pts
A Book That Prints Nicely
Create a class called Book with:
__init__(self, title, author, year)that stores all three values.__str__that returns the textTitle (Year) by Author.
Create book1 = Book("Python Basics", "Selam", 2024) and book2 = Book("Eritrean Stories", "Abel", 2019), then print both objects.
Expected output:
Python Basics (2024) by Selam Eritrean Stories (2019) by Abel
Checklist
- Define a class called
Bookwhose__init__stores the title, author and year. - Add a
__str__method that returns the text in the formTitle (Year) by Author. - Create
book1andbook2and print both objects.
🔑 Solution
If you view the solution before passing, you earn half points for this exercise. You still need to type it and press Check to finish.
How it works, step by step
Point at a step to highlight its lines. Type the solution yourself and press Check answer to finish.
