Spaces:
Running
on
Zero
Running
on
Zero
File size: 879 Bytes
164aab4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
from dataclasses import dataclass
from typing import List
@dataclass
class Book:
"""Represents a book with title and author"""
title: str
author: str
class Library:
"""Represents a library with a collection of books"""
def __init__(self):
self.books: List[Book] = []
def add_book(self, book: Book):
"""Adds a book to the library"""
self.books.append(book)
def list_books(self):
"""Lists all books in the library"""
for book in self.books:
print(f"Title: {book.title}, Author: {book.author}")
def main():
"""Main entry point of the application"""
library = Library()
book1 = Book("To Kill a Mockingbird", "Harper Lee")
book2 = Book("1984", "George Orwell")
library.add_book(book1)
library.add_book(book2)
library.list_books()
if __name__ == "__main__":
main() |