2015-05-13 42 views
0

我正在爲基本圖書館管理系統編寫代碼,我有一個ID號,書名和作者的txt文件。我已經到了登錄系統請求身份證號碼等階段,我可以搜索書籍。現在我需要把它做出來,以便我可以查看這本書...我已經得到了它,所以它會搜索這本書,但是我需要將ID號碼附加到txt文件中的正確書本上。我已經知道它只是附加到最後一個對象。任何指針都會很有幫助。謝謝。檢出圖書管理系統中的圖書

用於搜索圖書本次代碼...

while True: 
    n=float(raw_input('Please enter your ID ')) 
    if n in range (1000,10000): 

    break 
print 'ID is incorrect, please try again' 


with open("txt.txt") as searchfile: 
    found = False 
    while not found: 
     b=str(raw_input('please enter a book ')) 
     if b == '': 
     break # allow the search-loop to quit on no input 
     for line in searchfile: 
      if b in line: 
       print line 
       found = True 
       break 
     else: 
      print 'Please try again' 
      searchfile.seek(0) # reset file to the beginning for next search 


searchfile.close() 

這所有的作品^^^然後我得檢查出書和得到這個下面的代碼:

find_book=[] 
    with open('txt.txt') as input_file: 
     lines = [line.rstrip().split('\t') 
       for line in input_file.readlines()] 



if(find_book('0',3))==0: 
    print 'availabile' 
+0

在這樣一個普遍的問題中,你不可能得到幫助。你能否顯示你當前的代碼並給出一個詳細的例子,說明它不能在你需要的時候工作?這樣,你可能會得到答案。事實上,你的問題可能會被關閉。 – Blckknght

+1

已更新它 – toby

+2

Eek爲什麼要用文本文件而不是數據庫來做這件事? –

回答

1

類庫

Librarians=[["Prashanth","1234"],["Swetha","4321"]] 
Students=[["RajaShekar","1111"],["Sandeep","2222"],["Manasa","3333"],["Manoj","4444"],["RamaKrishna","5555"],["Teja","6666"],["Bhavani","7777"],["Sandilya","9999"]] 
Rack_Book=[["Physics","Einstin","1000"],["Physics","Einstin","1001"],["Physics","Edison","1002"],["Physics","Einstin","1003"],["Physics","Einstin","1004"],\ 
     ["Chemistry","Einstin","2000"],["Chemistry","Thamos","2001"],["Chemistry","Einstin","2002"],["Chemistry","Nobel","2003"],["Chemistry","Einstin","2004"]] 
Dispatch_Book=[] 
def Change_Login(self,name,pin): 
    if [name,pin] not in lib.Librarians: 
     Librarians=self.Librarians.append([name,pin]) 
     print("Successfully Changed login details") 
    else: 
     print("Entered same details only") 
def Update_Book(self,name,author,Bid): 
    if [name,author,Bid] not in lib.Rack_Book: 

     Rack_Book=self.Rack_Book.append([name,author,Bid]) 
     #print(lib.Rack_Book) 
     print("Update Successfully:",[name,author,Bid]) 
    else: 
     print("Book already available with same details") 
def Details_Books(self): 
    print("--------------------------------------------------") 
    print("Book name"," "*9,"Author Name"," "*9,"Book ID") 
    print("--------------------------------------------------") 


    for i in range(len(lib.Rack_Book)): 
     print(lib.Rack_Book[i][0]," "*(20-len(lib.Rack_Book[i][0])),lib.Rack_Book[i][1]," "*(20-len(lib.Rack_Book[i][1])),lib.Rack_Book[i][2]) 
     print("___________________________________________________") 

    print("\nNo of avaliable Books are:",len(lib.Rack_Book)) 

def Add_Students(self,name,pin): 
    if [name,pin] not in lib.Students: 
     Students=self.Students.append([name,pin]) 
     print("Successfully Added with details",[name,pin]) 
    else: 
     print("Students already available with details") 
def Delete_Students(self,name,pin): 
    if [name,pin] in lib.Students: 
     Students=self.Students.remove([name,pin]) 
     print("Successfully deleted details",[name,pin]) 
    else: 
     print("No students available with details")  
def Details_Students(self): 
    print("-------------------------------") 
    print("Sudent name"," "*9,"R.No") 
    print("-------------------------------") 

    for i in range(len(lib.Students)): 
     print(lib.Students[i][0]," "*(20-len(lib.Students[i][0])),lib.Students[i][1]) 
     print("_______________________________") 
    print("\nNo of Students are:",len(lib.Students)) 
def Collect_Books(self,name,author,Bid): 
    if [name,author,Bid] in lib.Rack_Book: 
     Dispatch_Book=self.Dispatch_Book.append([name,author,Bid]) 
     Rack_Book=self.Rack_Book.remove([name,author,Bid]) 
     print("Book collected succesfully:" ,[name,author,Bid]) 
    else: 
     print("Enter details wrong:")  
def Return_Book(self,name,author,Bid): 
    if [name,author,Bid] in lib.Dispatch_Book: 
     Dispatch_Book=self.Dispatch_Book.remove([name,author,Bid]) 
     Rack_Book=lib.Rack_Book.append([name,author,Bid]) 
     print("Return Successfully:",[name,author,Bid]) 
    else: 
     print("Enter details wrong:") 


lib=Library() 
print("Welcome to Library") 
while(True): 
print('''Select your Option 
1:Librarian Login 
2:Student Login 
3:Exit''') 

opt1=int(input("Please Enter your option:")) 

if opt1==1: 
    i=1 
    while (i<4): 
     usrlib=input("Please Enter your Name:") 
     pinlib=input("Please Enter your Login PIN:") 

     if [usrlib,pinlib] in lib.Librarians: 
      print("Access Granted") 
      i=5 
      while(True): 
       print('''Select your Option 
       0:Change Username or Password 
       1:Add Books 
       2:Books Details 
       3:Add Students 
       4:Remove Students 
       5:Students details 
       6:Exit or Back''') 
       opt2=int(input("Please Enter your option:")) 
       if opt2==0: 
        usrlib1=input("Please Enter User Name to chane:") 
        pinlib2=input("Please Enter Login PIN to change:") 
        lib.Change_Login(usrlib1,pinlib2) 

       elif opt2==1: 
        name=input("Please Enter your Book Name:") 
        author=input("Please Enter your Book Author:") 
        Bid=input("Please Enter your Book Id:") 
        lib.Update_Book(name.capitalize(),author.capitalize(),Bid) 

       elif opt2==2: 
        lib.Details_Books() 

       elif opt2==3: 
        name=input("Please Enter Student Name:") 
        pin=input("Please Enter Student R.No:") 
        lib.Add_Students(name.capitalize(),pin) 
       elif opt2==4: 
        name=input("Please Enter Student Name:") 
        pin=input("Please Enter Student R.No:") 
        lib.Delete_Students(name.capitalize(),pin)  
       elif opt2==5: 
        lib.Details_Students() 
       elif opt2==6:  
        print("Back to Menu") 
        break 
       else: 
        print("Wrong input") 
        continue 


     else: 
      print("Access Denied \nUser name or PIN Entered wrong") 
      print("\nYou have more",(3-i),"attempts") 
      i+=1 
      if i==4: 
       print("Failed login within 3 attempts") 
elif opt1==2: 
    i=1 
    while (i<4): 
     usrstd=input("Please Enter your Name:") 
     pinstd=input("Please Enter your R.No:") 

     if [usrstd,pinstd] in lib.Students: 
      print("Access Granted") 
      i=5 
      while(True): 
       print('''Select your Option 
        1:Collect Book 
        2:Return Books 
        3:Exit or Back 
        ''') 
       opt2=int(input("Please Enter your option:")) 
       if opt2==1: 
        print("Availablie Books are:\n") 
        lib.Details_Books() 
        name=input("Please Enter your Book Name:") 
        author=input("Please Enter your Book Author:") 
        Bid=input("Please Enter your Book Id:") 
        lib.Collect_Books(name.capitalize(),author.capitalize(),Bid) 
       elif opt2==2: 
        name=input("Please Enter your Book Name:") 
        author=input("Please Enter your Book Author:") 
        Bid=input("Please Enter your Book Id:") 
        lib.Return_Book(name.capitalize(),author.capitalize(),Bid) 
       elif opt2==3: 
        print("Back to Menu") 
        break 

       else: 
        print("Wrong input") 


     else: 
      print("Access Denied \nUser name or PIN Entered wrong") 
      print("\nYou have more",(3-i),"attempts") 
      i+=1 
      if i==4: 
       print("Failed login within 3 attempts") 

elif opt1==3: 
    print("Exit Successfully") 
    break 

else: 
    print("Wrong input") 

這是圖書館管理程序,我最初拿一些書,一些學生和兩位圖書館員。圖書管理員只能查看書籍的詳細信息,學生的詳細信息,他們只能添加或刪除學生登錄信息。學生在那裏登錄詳細信息,並從現有書籍中收集書籍,並返回所拍的書籍。如果學生收集書籍,書籍詳細信息會附加到派發的列表中並從可用列表中刪除。