pythonCopy code
from mypackage import greetings
pythonCopy code
print(greetings.say_hello("Bob"))
pythonCopy code
import modulea
# Print all names defined in modulea
print(dir(modulea))
class Book:
def __init__(self, title, author, price):
self.title = title
self.author = author
self.price = price
def display(self):
print(f"Book: {self.title}\nAuthor: {self.author}\nPrice: ${self.price}")
class Bookstore:
def __init__(self, name):
self.name = name
self.books = []
def add_book(self, book):
self.books.append(book)
def show_books(self):
print(f"Books available in {self.name}:")
for book in self.books:
book.display()
# program1.py
import class_definitions
# Assuming you have a Book class defined somewhere,
# either in this file or imported from another
# You need to ensure that the Book class is also accessible here
# Creating instances of Book
book1 = class_definitions.Book("The Alchemist", "Paulo Coelho", 15.99)
book2 = class_definitions.Book("To Kill a Mockingbird", "Harper Lee", 12.99)
# Creating an instance of Bookstore
my_bookstore = class_definitions.Bookstore("Book Haven")
# Adding books to the bookstore
my_bookstore.add_book(book1)
my_bookstore.add_book(book2)
# Displaying all books in the bookstore
my_bookstore.show_books()