2015-05-13 40 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") 

这是图书馆管理程序,我最初拿一些书,一些学生和两位图书馆员。图书管理员只能查看书籍的详细信息,学生的详细信息,他们只能添加或删除学生登录信息。学生在那里登录详细信息,并从现有书籍中收集书籍,并返回所拍的书籍。如果学生收集书籍,书籍详细信息会附加到派发的列表中并从可用列表中删除。