0% found this document useful (0 votes)
43 views23 pages

auto3sasi6572

This document presents a simple Library Management System (LMS) implemented in Python. It includes classes for managing books and their statuses, as well as a menu-driven interface for adding, borrowing, returning, and viewing books. The code is structured for ease of understanding and usability.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views23 pages

auto3sasi6572

This document presents a simple Library Management System (LMS) implemented in Python. It includes classes for managing books and their statuses, as well as a menu-driven interface for adding, borrowing, returning, and viewing books. The code is structured for ease of understanding and usability.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 23

Skip to content

Chat history

ChatGPT
ChatGPT
GPT Icon
Text-Based Flowchart Maker AI
Explore GPTs

Library
8
Today
Yesterday
Previous 7 Days
Previous 30 Days
Upgrade plan
More access to the best models
You said:
class Book:
def __init__(self, title, author, status):
self.title = title
self.author = author
self.status = status

def __str__(self):
return f"{self.title} by {self.author} ({self.status})"

class LibraryManagementSystem:
def __init__(self):
self.books = []

def add_book(self, book):


self.books.append(book)

def borrow_book(self, title):


for book in self.books:
if book.title == title and book.status == "Available":
book.status = "Borrowed"
print(f"You have borrowed {book.title}.")
return
print(f"{title} is not available.")

def return_book(self, title):


for book in self.books:
if book.title == title and book.status == "Borrowed":
book.status = "Available"
print(f"You have returned {book.title}.")
return
print(f"{title} is not borrowed.")

def main():
lms = LibraryManagementSystem()

# Add some books


lms.add_book(Book("To Kill a Mockingbird", "Harper Lee", "Available"))
lms.add_book(Book("1984", "George Orwell", "Available"))
lms.add_book(Book("Pride and Prejudice", "Jane Austen", "Available"))
while True:
print("1. Borrow Book")
print("2. Return Book")
print("3. List Books")
print("4. Exit")

option = input("Choose an option: ")

if option == "1":
title = input("Enter book title to borrow: ")
lms.borrow_book(title)
elif option == "2":
title = input("Enter book title to return: ")
lms.return_book(title)
elif option == "3":
for book in lms.books:
print(book)
elif option == "4":
break
else:
print("Invalid option. Please choose again.")

if __name__ == "__main__":
main()

can this be written more easily without changing output


ChatGPT said:
Yes! Your code is already quite clear and well-structured. However, it can be
simplified slightly while keeping the same functionality and output. Here's a
cleaner version with reduced repetition and a more concise design:

class Book:
def __init__(self, title, author, status="Available"):
self.title = title
self.author = author
self.status = status

def __str__(self):
return f"{self.title} by {self.author} ({self.status})"

class LibraryManagementSystem:
def __init__(self):
self.books = []

def add_book(self, title, author):


self.books.append(Book(title, author))

def find_book(self, title):


return next((book for book in self.books if book.title == title), None)

def borrow_book(self, title):


book = self.find_book(title)
if book and book.status == "Available":
book.status = "Borrowed"
print(f"You have borrowed {book.title}.")
else:
print(f"{title} is not available.")

def return_book(self, title):


book = self.find_book(title)
if book and book.status == "Borrowed":
book.status = "Available"
print(f"You have returned {book.title}.")
else:
print(f"{title} is not borrowed.")

def main():
lms = LibraryManagementSystem()
lms.add_book("To Kill a Mockingbird", "Harper Lee")
lms.add_book("1984", "George Orwell")
lms.add_book("Pride and Prejudice", "Jane Austen")

options = {
"1": lambda: lms.borrow_book(input("Enter book title to borrow: ")),
"2": lambda: lms.return_book(input("Enter book title to return: ")),
"3": lambda: print("\n".join(str(book) for book in lms.books)),
"4": lambda: exit()
}

while True:
print("\n1. Borrow Book\n2. Return Book\n3. List Books\n4. Exit")
choice = input("Choose an option: ")
options.get(choice, lambda: print("Invalid option. Please choose again."))
()

if __name__ == "__main__":
main()
Improvements made:
Default status to "Available" in Book class.

Created a helper find_book() method to avoid repeating search logic.

Used a dictionary to clean up the menu option handling.

Condensed repetitive lines like printing the book list.

Let me know if you'd like it even shorter or converted into a different format
(like using a GUI or storing books in a file).

You said:
its ok no need but remove comment lines and gie easy book names for this easy
program

class Book:
def __init__(self, title, author, status):
self.title = title
self.author = author
self.status = status

def __str__(self):
return f"{self.title} by {self.author} ({self.status})"

class LibraryManagementSystem:
def __init__(self):
self.books = []

def add_book(self, book):


self.books.append(book)

def borrow_book(self, title):


for book in self.books:
if book.title == title and book.status == "Available":
book.status = "Borrowed"
print(f"You have borrowed {book.title}.")
return
print(f"{title} is not available.")

def return_book(self, title):


for book in self.books:
if book.title == title and book.status == "Borrowed":
book.status = "Available"
print(f"You have returned {book.title}.")
return
print(f"{title} is not borrowed.")

def main():
lms = LibraryManagementSystem()

# Add some books


lms.add_book(Book("To Kill a Mockingbird", "Harper Lee", "Available"))
lms.add_book(Book("1984", "George Orwell", "Available"))
lms.add_book(Book("Pride and Prejudice", "Jane Austen", "Available"))

while True:
print("1. Borrow Book")
print("2. Return Book")
print("3. List Books")
print("4. Exit")

option = input("Choose an option: ")

if option == "1":
title = input("Enter book title to borrow: ")
lms.borrow_book(title)
elif option == "2":
title = input("Enter book title to return: ")
lms.return_book(title)
elif option == "3":
for book in lms.books:
print(book)
elif option == "4":
break
else:
print("Invalid option. Please choose again.")

if __name__ == "__main__":
main()
ChatGPT said:
Here’s your code cleaned up—comments removed and book names simplified to make it
more beginner-friendly:

class Book:
def __init__(self, title, author, status):
self.title = title
self.author = author
self.status = status

def __str__(self):
return f"{self.title} by {self.author} ({self.status})"

class LibraryManagementSystem:
def __init__(self):
self.books = []

def add_book(self, book):


self.books.append(book)

def borrow_book(self, title):


for book in self.books:
if book.title == title and book.status == "Available":
book.status = "Borrowed"
print(f"You have borrowed {book.title}.")
return
print(f"{title} is not available.")

def return_book(self, title):


for book in self.books:
if book.title == title and book.status == "Borrowed":
book.status = "Available"
print(f"You have returned {book.title}.")
return
print(f"{title} is not borrowed.")

def main():
lms = LibraryManagementSystem()

lms.add_book(Book("Book A", "Author 1", "Available"))


lms.add_book(Book("Book B", "Author 2", "Available"))
lms.add_book(Book("Book C", "Author 3", "Available"))

while True:
print("1. Borrow Book")
print("2. Return Book")
print("3. List Books")
print("4. Exit")

option = input("Choose an option: ")

if option == "1":
title = input("Enter book title to borrow: ")
lms.borrow_book(title)
elif option == "2":
title = input("Enter book title to return: ")
lms.return_book(title)
elif option == "3":
for book in lms.books:
print(book)
elif option == "4":
break
else:
print("Invalid option. Please choose again.")
if __name__ == "__main__":
main()
Let me know if you want a version that saves books to a file or something more
advanced later!

You said:
class Employee:
def __init__(self, id, name, department):
self.id = id
self.name = name
self.department = department

def __str__(self):
return f"ID: {self.id}, Name: {self.name}, Department: {self.department}"

class EmployeeManagementSystem:
def __init__(self):
self.employees = []

def add_employee(self, employee):


self.employees.append(employee)

def remove_employee(self, id):


self.employees = [employee for employee in self.employees if employee.id !=
id]

def view_employees(self):
for employee in self.employees:
print(employee)

def main():
ems = EmployeeManagementSystem()

while True:
print("1. Add Employee")
print("2. Remove Employee")
print("3. View Employees")
print("4. Exit")

option = input("Choose an option: ")

if option == "1":
id = int(input("Enter employee ID: "))
name = input("Enter employee name: ")
department = input("Enter employee department: ")
employee = Employee(id, name, department)
ems.add_employee(employee)
elif option == "2":
id = int(input("Enter employee ID to remove: "))
ems.remove_employee(id)
elif option == "3":
ems.view_employees()
elif option == "4":
break
else:
print("Invalid option. Please choose again.")

if __name__ == "__main__":
main()

like this givefor lms system also easy program


ChatGPT said:
Sure! Here's an easy and clean version of the Library Management System (LMS),
matching the simplicity and structure of your EmployeeManagementSystem example:

class Book:
def __init__(self, title, author, status):
self.title = title
self.author = author
self.status = status

def __str__(self):
return f"Title: {self.title}, Author: {self.author}, Status: {self.status}"

class LibraryManagementSystem:
def __init__(self):
self.books = []

def add_book(self, book):


self.books.append(book)

def borrow_book(self, title):


for book in self.books:
if book.title == title and book.status == "Available":
book.status = "Borrowed"
print(f"You borrowed: {book.title}")
return
print("Book not available")

def return_book(self, title):


for book in self.books:
if book.title == title and book.status == "Borrowed":
book.status = "Available"
print(f"You returned: {book.title}")
return
print("Book was not borrowed")

def view_books(self):
for book in self.books:
print(book)

def main():
lms = LibraryManagementSystem()

while True:
print("1. Add Book")
print("2. Borrow Book")
print("3. Return Book")
print("4. View Books")
print("5. Exit")

option = input("Choose an option: ")

if option == "1":
title = input("Enter book title: ")
author = input("Enter author name: ")
book = Book(title, author, "Available")
lms.add_book(book)
elif option == "2":
title = input("Enter book title to borrow: ")
lms.borrow_book(title)
elif option == "3":
title = input("Enter book title to return: ")
lms.return_book(title)
elif option == "4":
lms.view_books()
elif option == "5":
break
else:
print("Invalid option. Try again.")

if __name__ == "__main__":
main()
This version is structured the same way as your employee system—simple, clean, and
easy to follow. Let me know if you want a version that saves data to a file or
includes search functionality too!

You said:
class Book:
def __init__(self, title, author, status):
self.title = title
self.author = author
self.status = status

can you give this some easily


def __str__(self):
return f"Title: {self.title}, Author: {self.author}, Status: {self.status}"
class LibraryManagementSystem:
def __init__(self):
self.books = []
def add_book(self, book):
self.books.append(book)
def borrow_book(self, title):
for book in self.books:
if book.title == title and book.status == "Available":
book.status = "Borrowed"
print(f"You borrowed: {book.title}")
return
print("Book not available")
def return_book(self, title):
for book in self.books:
if book.title == title and book.status == "Borrowed":
book.status = "Available"
print(f"You returned: {book.title}")
return
print("Book was not borrowed")
def view_books(self):
for book in self.books:
print(book)
def main():
lms = LibraryManagementSystem()
while True:
print("1. Add Book")
print("2. Borrow Book")
print("3. Return Book")
print("4. View Books")
print("5. Exit")
option = input("Choose an option: ")
if option == "1":
title = input("Enter book title: ")
author = input("Enter author name: ")
book = Book(title, author, "Available")
lms.add_book(book)
elif option == "2":
title = input("Enter book title to borrow: ")
lms.borrow_book(title)
elif option == "3":
title = input("Enter book title to return: ")
lms.return_book(title)
elif option == "4":
lms.view_books()
elif option == "5":
break
else:
print("Invalid option. Try again.")
if __name__ == "__main__":
main()
ChatGPT said:
Sure! Here's a very simple and easy-to-read version of your Library Management
System code. I've made the class definitions and print messages a bit more
beginner-friendly without changing the functionality:

class Book:
def __init__(self, title, author, status):
self.title = title
self.author = author
self.status = status

def __str__(self):
return "Title: " + self.title + ", Author: " + self.author + ", Status: " +
self.status

class LibraryManagementSystem:
def __init__(self):
self.books = []

def add_book(self, book):


self.books.append(book)

def borrow_book(self, title):


for book in self.books:
if book.title == title and book.status == "Available":
book.status = "Borrowed"
print("You borrowed:", book.title)
return
print("Book not available")
def return_book(self, title):
for book in self.books:
if book.title == title and book.status == "Borrowed":
book.status = "Available"
print("You returned:", book.title)
return
print("Book was not borrowed")

def view_books(self):
for book in self.books:
print(book)

def main():
lms = LibraryManagementSystem()

while True:
print("1. Add Book")
print("2. Borrow Book")
print("3. Return Book")
print("4. View Books")
print("5. Exit")

option = input("Choose an option: ")

if option == "1":
title = input("Enter book title: ")
author = input("Enter author name: ")
book = Book(title, author, "Available")
lms.add_book(book)
elif option == "2":
title = input("Enter book title to borrow: ")
lms.borrow_book(title)
elif option == "3":
title = input("Enter book title to return: ")
lms.return_book(title)
elif option == "4":
lms.view_books()
elif option == "5":
break
else:
print("Invalid option. Try again.")

if __name__ == "__main__":
main()
What's made simpler:
Used + in __str__ for easier understanding.

Messages like "You borrowed:" and "You returned:" are easy to read.

No extra formatting — just basic strings and logic.

Let me know if you want the same for another topic or system!

You said:
simple and easy
ChatGPT said:
Absolutely! Here's a super simple and easy version of your Library Management
System — very beginner-friendly and easy to understand:
class Book:
def __init__(self, title, author, status):
self.title = title
self.author = author
self.status = status

def __str__(self):
return "Title: " + self.title + ", Author: " + self.author + ", Status: " +
self.status

class Library:
def __init__(self):
self.books = []

def add_book(self, book):


self.books.append(book)

def borrow_book(self, title):


for book in self.books:
if book.title == title and book.status == "Available":
book.status = "Borrowed"
print("Book borrowed:", book.title)
return
print("Book not available")

def return_book(self, title):


for book in self.books:
if book.title == title and book.status == "Borrowed":
book.status = "Available"
print("Book returned:", book.title)
return
print("Book was not borrowed")

def show_books(self):
for book in self.books:
print(book)

def main():
library = Library()

while True:
print("1. Add Book")
print("2. Borrow Book")
print("3. Return Book")
print("4. Show Books")
print("5. Exit")

choice = input("Choose: ")

if choice == "1":
title = input("Book title: ")
author = input("Author name: ")
book = Book(title, author, "Available")
library.add_book(book)
elif choice == "2":
title = input("Book to borrow: ")
library.borrow_book(title)
elif choice == "3":
title = input("Book to return: ")
library.return_book(title)
elif choice == "4":
library.show_books()
elif choice == "5":
break
else:
print("Invalid choice")

if __name__ == "__main__":
main()
Simple terms used:
Class names: Book, Library

Method names: add_book, borrow_book, return_book, show_books

Easy print statements and input prompts.

Let me know if you want a version with file saving or search next!

You said:
easy functions
ChatGPT said:
Got it! Here's an ultra-easy version of the Library Management System — with very
simple function names and short logic, great for beginners:

class Book:
def __init__(self, title, author):
self.title = title
self.author = author
self.status = "Available"

def __str__(self):
return "Title: " + self.title + ", Author: " + self.author + ", Status: " +
self.status

class Library:
def __init__(self):
self.books = []

def add(self, book):


self.books.append(book)

def borrow(self, title):


for book in self.books:
if book.title == title and book.status == "Available":
book.status = "Borrowed"
print("Borrowed:", book.title)
return
print("Not available")

def give_back(self, title):


for book in self.books:
if book.title == title and book.status == "Borrowed":
book.status = "Available"
print("Returned:", book.title)
return
print("Not borrowed")

def show(self):
for book in self.books:
print(book)

def main():
lib = Library()

while True:
print("1. Add")
print("2. Borrow")
print("3. Return")
print("4. Show")
print("5. Exit")

choice = input("Choose: ")

if choice == "1":
title = input("Book title: ")
author = input("Author: ")
lib.add(Book(title, author))
elif choice == "2":
title = input("Book to borrow: ")
lib.borrow(title)
elif choice == "3":
title = input("Book to return: ")
lib.give_back(title)
elif choice == "4":
lib.show()
elif choice == "5":
break
else:
print("Wrong choice")

if __name__ == "__main__":
main()
Changes made for simplicity:
Function names are short: add, borrow, give_back, show

No extra formatting

Easy-to-read print messages

Fewer words, same logic

Let me know if you want an even smaller version, or to turn it into a game or
project!

You said:
single name functions
ChatGPT said:
Perfect! Here's the easiest version of the Library Management System using one-word
function names only — super simple and beginner-friendly:

class Book:
def __init__(self, title, author):
self.title = title
self.author = author
self.status = "Available"

def __str__(self):
return "Title: " + self.title + ", Author: " + self.author + ", Status: " +
self.status

class Library:
def __init__(self):
self.books = []

def add(self, book):


self.books.append(book)

def borrow(self, title):


for book in self.books:
if book.title == title and book.status == "Available":
book.status = "Borrowed"
print("Borrowed:", book.title)
return
print("Not available")

def returnbook(self, title):


for book in self.books:
if book.title == title and book.status == "Borrowed":
book.status = "Available"
print("Returned:", book.title)
return
print("Not borrowed")

def show(self):
for book in self.books:
print(book)

def main():
lib = Library()

while True:
print("1. Add")
print("2. Borrow")
print("3. Return")
print("4. Show")
print("5. Exit")

choice = input("Choose: ")

if choice == "1":
title = input("Book title: ")
author = input("Author: ")
lib.add(Book(title, author))
elif choice == "2":
title = input("Book to borrow: ")
lib.borrow(title)
elif choice == "3":
title = input("Book to return: ")
lib.returnbook(title)
elif choice == "4":
lib.show()
elif choice == "5":
break
else:
print("Wrong choice")
if __name__ == "__main__":
main()
One-word functions:
add

borrow

returnbook

show

Let me know if you want the same style for a student or employee system too!

You said:
implement uml lms system in python as add easyily
ChatGPT said:
Sure! Here's a very simple UML-style implementation of a Library Management System
in Python, focusing only on the Add Book feature (easy version):

✅ UML-Like Design (in text)


Class: Book
- title: str
- author: str
- status: str
+ __str__()

Class: Library
- books: list
+ add(book: Book)
+ show()
✅ Python Code (Simple Add Only)
class Book:
def __init__(self, title, author):
self.title = title
self.author = author
self.status = "Available"

def __str__(self):
return "Title: " + self.title + ", Author: " + self.author + ", Status: " +
self.status

class Library:
def __init__(self):
self.books = []

def add(self, book):


self.books.append(book)
print("Book added:", book.title)

def show(self):
for book in self.books:
print(book)

def main():
lib = Library()

while True:
print("1. Add Book")
print("2. Show Books")
print("3. Exit")

choice = input("Choose: ")

if choice == "1":
title = input("Enter title: ")
author = input("Enter author: ")
new_book = Book(title, author)
lib.add(new_book)
elif choice == "2":
lib.show()
elif choice == "3":
break
else:
print("Invalid choice")

if __name__ == "__main__":
main()
✅ Output Example:
1. Add Book
2. Show Books
3. Exit
Choose: 1
Enter title: Python
Enter author: John
Book added: Python
Let me know if you want to add borrow, return, or a UML diagram using PlantUML or
draw.io style too!

You said:
borrow return also
ChatGPT said:
Great! Here's the easy Python program for a Library Management System with Add,
Borrow, Return, and Show features — all based on a simple UML-like design.

✅ UML-Like Design (Text)


Class: Book
- title: str
- author: str
- status: str
+ __str__()

Class: Library
- books: list
+ add(book: Book)
+ borrow(title: str)
+ returnbook(title: str)
+ show()
✅ Full Simple Python Code
class Book:
def __init__(self, title, author):
self.title = title
self.author = author
self.status = "Available"

def __str__(self):
return "Title: " + self.title + ", Author: " + self.author + ", Status: " +
self.status
class Library:
def __init__(self):
self.books = []

def add(self, book):


self.books.append(book)
print("Book added:", book.title)

def borrow(self, title):


for book in self.books:
if book.title == title and book.status == "Available":
book.status = "Borrowed"
print("Book borrowed:", book.title)
return
print("Book not available")

def returnbook(self, title):


for book in self.books:
if book.title == title and book.status == "Borrowed":
book.status = "Available"
print("Book returned:", book.title)
return
print("Book was not borrowed")

def show(self):
for book in self.books:
print(book)

def main():
lib = Library()

while True:
print("1. Add Book")
print("2. Borrow Book")
print("3. Return Book")
print("4. Show Books")
print("5. Exit")

choice = input("Choose: ")

if choice == "1":
title = input("Enter title: ")
author = input("Enter author: ")
new_book = Book(title, author)
lib.add(new_book)
elif choice == "2":
title = input("Enter title to borrow: ")
lib.borrow(title)
elif choice == "3":
title = input("Enter title to return: ")
lib.returnbook(title)
elif choice == "4":
lib.show()
elif choice == "5":
break
else:
print("Invalid choice")

if __name__ == "__main__":
main()
Let me know if you'd like the UML diagram in PlantUML or draw.io format too — I can
generate it for you!

You said:
except main function cant we make remaining program easily
ChatGPT said:
Yes, absolutely! 😄 You can make the rest of the program even easier by simplifying
names, reducing lines, and avoiding extra logic. Here's a super simplified version
of the Library Management System, where everything (except main()) is written as
easily as possible:

✅ Super Simple Python Code (Easy Style)


class Book:
def __init__(self, t, a):
self.t = t
self.a = a
self.s = "Available"

def __str__(self):
return f"Title: {self.t}, Author: {self.a}, Status: {self.s}"

class Library:
def __init__(self):
self.b = []

def add(self, bk):


self.b.append(bk)
print("Added:", bk.t)

def borrow(self, t):


for bk in self.b:
if bk.t == t and bk.s == "Available":
bk.s = "Borrowed"
print("Borrowed:", bk.t)
return
print("Not available")

def ret(self, t):


for bk in self.b:
if bk.t == t and bk.s == "Borrowed":
bk.s = "Available"
print("Returned:", bk.t)
return
print("Not borrowed")

def show(self):
for bk in self.b:
print(bk)
✅ main() function (kept the same as before)
def main():
lib = Library()

while True:
print("1. Add Book")
print("2. Borrow Book")
print("3. Return Book")
print("4. Show Books")
print("5. Exit")
ch = input("Choose: ")

if ch == "1":
t = input("Title: ")
a = input("Author: ")
lib.add(Book(t, a))
elif ch == "2":
t = input("Book to borrow: ")
lib.borrow(t)
elif ch == "3":
t = input("Book to return: ")
lib.ret(t)
elif ch == "4":
lib.show()
elif ch == "5":
break
else:
print("Invalid")

if __name__ == "__main__":
main()
✅ What’s made easier:
Short names: t, a, s, bk, b

Short function names: add, borrow, ret, show

Minimal print messages

No extra checks or formatting

Let me know if you want the same super-easy style for an Employee, Student, or
Inventory system!

You said:
hey what is it
ChatGPT said:
Sorry about that! It looks like I simplified the code too much and it became a bit
unclear. Let me explain and fix it for you!

In the version I gave you, I used:

Short variable names (t, a, s, bk, b) to keep it simple.

Shortened method names (add, borrow, ret, show) to make it even easier.

But this might have made it harder to understand because the names were not
descriptive enough. Here's a more clear but simple version, keeping things easy to
understand and still minimal.

✅ Simplified Library Management System


class Book:
def __init__(self, title, author):
self.title = title
self.author = author
self.status = "Available"

def __str__(self):
return f"Title: {self.title}, Author: {self.author}, Status: {self.status}"
class Library:
def __init__(self):
self.books = []

def add_book(self, book):


self.books.append(book)
print("Book added:", book.title)

def borrow_book(self, title):


for book in self.books:
if book.title == title and book.status == "Available":
book.status = "Borrowed"
print("You borrowed:", book.title)
return
print("This book is not available")

def return_book(self, title):


for book in self.books:
if book.title == title and book.status == "Borrowed":
book.status = "Available"
print("You returned:", book.title)
return
print("This book was not borrowed")

def show_books(self):
for book in self.books:
print(book)
✅ The Main Function (remains simple)
def main():
library = Library()

while True:
print("1. Add Book")
print("2. Borrow Book")
print("3. Return Book")
print("4. Show Books")
print("5. Exit")

choice = input("Choose: ")

if choice == "1":
title = input("Enter book title: ")
author = input("Enter author: ")
book = Book(title, author)
library.add_book(book)
elif choice == "2":
title = input("Enter book title to borrow: ")
library.borrow_book(title)
elif choice == "3":
title = input("Enter book title to return: ")
library.return_book(title)
elif choice == "4":
library.show_books()
elif choice == "5":
break
else:
print("Invalid choice")
if __name__ == "__main__":
main()
✅ What's Simplified:
Clearer method names: add_book, borrow_book, return_book, show_books

Readable variable names: title, author, status, book, library

Easy-to-understand print messages

Let me know if you need more details or if you'd like to add more features! 😊

You said:
i didnt tell like that iam unable to remember pls give easy less linesone except
main
ChatGPT said:
Got it! You want a super simple version with fewer lines and easy-to-remember code.
Here’s a much simpler version without any unnecessary complexity:

✅ Simplified Library Management System (without main function)


class Book:
def __init__(self, title, author):
self.title = title
self.author = author
self.status = "Available"

def __str__(self):
return f"{self.title} by {self.author} ({self.status})"

class Library:
def __init__(self):
self.books = []

def add(self, title, author):


self.books.append(Book(title, author))

def borrow(self, title):


for book in self.books:
if book.title == title and book.status == "Available":
book.status = "Borrowed"
print(f"Borrowed: {book.title}")
return
print("Not available")

def return_book(self, title):


for book in self.books:
if book.title == title and book.status == "Borrowed":
book.status = "Available"
print(f"Returned: {book.title}")
return
print("Not borrowed")

def show(self):
for book in self.books:
print(book)
✅ Key Changes
Short function names: add, borrow, return_book, show

Easy variable names: title, author, status, book, books


No extra comments or details—straight to the point.

This keeps the program simple and easy to remember, with the main focus on just
adding, borrowing, returning, and showing books.

Let me know if you'd like any further simplification!

You said:
add main function also and give easily
ChatGPT said:
Sure! Here's a very simplified version of the Library Management System, including
the main function, while keeping everything easy to remember:

✅ Complete Simple Code with main()


class Book:
def __init__(self, title, author):
self.title = title
self.author = author
self.status = "Available"

def __str__(self):
return f"{self.title} by {self.author} ({self.status})"

class Library:
def __init__(self):
self.books = []

def add(self, title, author):


self.books.append(Book(title, author))

def borrow(self, title):


for book in self.books:
if book.title == title and book.status == "Available":
book.status = "Borrowed"
print(f"Borrowed: {book.title}")
return
print("Not available")

def return_book(self, title):


for book in self.books:
if book.title == title and book.status == "Borrowed":
book.status = "Available"
print(f"Returned: {book.title}")
return
print("Not borrowed")

def show(self):
for book in self.books:
print(book)

def main():
library = Library()

while True:
print("1. Add Book")
print("2. Borrow Book")
print("3. Return Book")
print("4. Show Books")
print("5. Exit")
choice = input("Choose: ")

if choice == "1":
title = input("Enter title: ")
author = input("Enter author: ")
library.add(title, author)
elif choice == "2":
title = input("Enter book title to borrow: ")
library.borrow(title)
elif choice == "3":
title = input("Enter book title to return: ")
library.return_book(title)
elif choice == "4":
library.show()
elif choice == "5":
break
else:
print("Invalid choice")

if __name__ == "__main__":
main()
✅ What’s easy about this version:
Short function names: add, borrow, return_book, show

Simple variables: title, author, status, book, library

Main function loop: Simple options to add, borrow, return, or show books.

This version should be very easy to remember and use. You can quickly add or manage
books with the simple options in the main() loop.

Let me know if you'd like more changes! 😊

ChatGPT can make mistakes. Check important info.


?

You might also like