You are on page 1of 4

SOURCE CODE

Class Library:

Def __init__(self, book_name, author, pages, price):

Self.book_name = book_name

Self.author = author

Self.pages = pages

Self.price = price

Def __str__(self):

Return f”{self.book_name}\t {self.author}\t {self.pages}\t {self.price}”

# Driver Code

If __name__ == “__main__”:

# Create an array of Library objects

Lib = []
# Keep the track of the number of

# of books available in the library

Count = 0

# Iterate the loop

While True:

Print(“\n\n********######WELCOME TO E-LIBRARY #####********\n”)

Print(“1. Add book information\n2. Display book information\n”,

“3. List all books of given author\n4. List the count of books in the library\n5. Exit\n”)

# Enter the book details

Input_choice = input(“Enter one of the above: “)

# Process the input

If input_choice == ‘1’:

Book_name = input(“Enter book name = “)


Author = input(“Enter author name = “)

Pages = int(input(“Enter pages = “))

Price = float(input(“Enter price = “))

Lib.append(Library(book_name, author, pages, price))

Count += 1

Elif input_choice == ‘2’:

Print(“you have entered the following information”)

For book in lib:

Print(book)

Elif input_choice == ‘3’:

Ar_nm = input(“Enter author name : “)

For book in lib:

If book.author == ar_nm:

Print(book)

Elif input_choice == ‘4’:


Print(f”\nNo of books in library : {count}\n”)

Elif input_choice == ‘5’:

Exit(0)

You might also like