(1) 创建一个Library的类的实例,myLittleLibrary,其中预存有以下三本书: Java程序设计,张三著,45元 Java核心设计,李四著,50元 Java程序设计,王五著,38元
时间: 2024-05-27 12:12:00 浏览: 116
class Book:
def __init__(self, title, author, price):
self.title = title
self.author = author
self.price = price
class Library:
def __init__(self, books):
self.books = books
def display_books(self):
for book in self.books:
print(f"{book.title}, {book.author}著,{book.price}元")
books = [
Book("Java程序设计", "张三", 45),
Book("Java核心设计", "李四", 50),
Book("Java程序设计", "王五", 38)
]
myLittleLibrary = Library(books)
myLittleLibrary.display_books()
阅读全文