Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
when im pressing 3 and giving input its giving me attribut error please help me


Error:
AttributeError: 'Student' object has no attribute 'Book_list'


What I have tried:

class Library:
    
    def show(self):
        self.Book_list=["English","Python","Urdu"]
        print(f"\n\nHellow! You can see the available books Below:\n")
        print("\n".join(map(str,self.Book_list)))
    def __init__(self):
        self.BookName=input("\nEnter The Book Name.....").capitalize()
        return self.BookName
     
    def Remove(self):
        if self.BookName in self.Book_list:
            self.Book_list.remove(self.BookName)
            print("You have Got this Book Successfully! Please return the book before 30 Days. ThankYou!")
            return self.Book_list
        else:
            print("Book not Available! Please Request later!")
    def Append(self):
            self.Book_list.append(self.BookName)
            print("Hi Thanks for Returning the Book")
   
class Student():
    def Show_Books(self):return Library.show(self)
    def Borrow(self):return Library.show(self),Library.__init__(self),Library.Remove(self)     
    def Return(self):return Library.__init__(self),Library.Append(self)

while(True):
    stu=Student()
    
    Msg=("\n\n\n====================== Hi Welcome To The SSUET Library ======================\n\nPlease Select The Option Below:\n\n Press '1' To See The Book's List. \n Press '2' For Borrow.\n Press '3' To Return The Book\n Press '4' for Quit")
    print(Msg)
    slc=int(input("Press the Button..........."))  
    if slc==1:stu.Show_Books()
    elif slc==2:stu.Borrow()
    elif slc==3:stu.Return()
    elif slc==4:
        print("Quit")
        break   
Posted
Updated 22-Aug-22 21:56pm

1 solution

Python
class Student():
    def Show_Books(self):return Library.show(self)
    def Borrow(self):return Library.show(self),Library.__init__(self),Library.Remove(self)     
    def Return(self):return Library.__init__(self),Library.Append(self)

You are passing a Student object reference (self) to a Library method. But Library methods expect self to be a Library object. And since Student and Library are totally separate classes this will not work. You cannot do direct calls in that way, you need to redesign your code.
 
Share this answer
 
Comments
CPallini 23-Aug-22 4:01am    
5.
Richard MacCutchan 23-Aug-22 4:11am    
Thanks Carlo. Certainly interesting piece of programming. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900