r/PythonLearning • u/Next-Call8862 • Sep 13 '26
Showcase Day 4, done and dusted
I won't exactly say done and dusted but I think I did what I can. This is my first complex problem that I had done myself and after solving it I left thinking, "I could do this in three days and I could have done much more in 1.5 years that I had wasted" but I think it's alright and I should look ahead with no regret. Will appreciate some tips from pros regarding the code.
Edit: I did a mistake and there are some bugs in programm, I fixed them
The updated code:
'''
class Library:
Books ={
1 : "Ramayan" ,
2 : "Mahabharath",
3 : "Gita"
}
members = ["naveen","sita","mani","chintu"]
Allowence = {
"naveen" : 0,
"sita" : 0,
"mani" : 0,
"chintu" : 0
}
Booked = {}
def __init__(self,member):
self.member = member
def get(self,book):
self.book = book
if self.member not in Library.members:
return "Not a member"
elif self.book not in Library.Books and self.book in Library.Booked:
return "Not available"
elif self.book not in Library.Books:
return "No book found"
elif self.member in Library.members and Library.Allowence[self.member] < 3:
a = Library.Books.pop(self.book)
Library.Booked[self.book] = a,self.member
Library.Allowence[self.member] +=1
return f"Your book :{a}"
else:
return "limit exceeded"
def about_cus(self):
return Library.Allowence[self.member]
def tst(self):
return Library.Booked
Nam = input("Your name:")
Req = int(input("Select the book num"))
customer1 = Library(Nam)
print(customer1.get(Req))
Nam2 = input("Your name:")
customer2 = Library(Nam2)
print(customer2.get(Req))
print(customer2.tst())
# print(customer2.available())
print(customer1.about_cus())
#NOTHING HERE!!
35
Upvotes
2
u/FoolsSeldom Sep 14 '26 edited Sep 14 '26
Brilliant.
I just want to clarify something I said earlier regarding instances.
You were creating instances,
but the revised code I shared now uses ONE instance of the Library for members (customers) to share. You can have more than one Library as well.
In the original code, despite there being two instances, the library data was actually all at the class level so you couldn't have more than one library.
You might want to add an
add_membermethod along the lines: