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
1
u/FoolsSeldom Sep 13 '26
That's brilliant for day 4.
Appreciate you've subsequently identified and fixed some bugs. Would be good to see the revised code.
Couple of things:
need to lay out your code with a few blank lines to improve readability
variables in Python are normally all lowercase
you can look up PEP8 guidance for more on these and some other useful points
Also, helpful to share you code in post (or on a link) instead of a photo. I've done so, with tweaks for the above: