python中的difflib get_close_matches错误

时间:2021-07-16 16:35:17

标签: python python-3.x typeerror difflib

所以,我尝试了下面的程序来运行除 get_close_matches() 部分之外的所有工作

代码:

from difflib import get_close_matches

class Library:

    def __init__(self,books):
        self.books=books
        
    def display_books(self):
        print("-----Available Books-----")
        for book in self.books:
            print(book)
    def borrow_books(self,borrow_book):
        if borrow_book in self.books:
            print("Get your book")
            self.books.remove(borrow_book)

        else:
            print("Book not available")
    def return_books(self,return_book):
        print("You have returned the book")
        self.books.append(return_book)
    
books=['C','C++','Java','Python']
o = Library(books)
msg="""
    Select the choices below
        1.Display Book
        2.Borrow Book
        3.Recieve Book
    """
while True:
    print(msg)
    ch=int(input("Enter your Choice : "))
    if ch == 1:
        o.display_books()
    elif ch == 2:
        book = input("Enter the book name to borrow : ")
        if book in books:
            o.borrow_books(book)
        elif get_close_matches(book, books):
            chooice=input("Did you mean %s"%get_close_matches(book,books)[0] ,"Enter Y for yes N for no")
            if chooice == "Y" or "y":
                print( books[get_close_matches(book,books)[0]])
            elif chooice == "N" or "n":
                print( "Entered book is not available")
        
    elif ch == 3:
        book = input("Enter the book name to return : ")
        o.return_books(book)
    else:
        print("Tq")
        quit()

这是代码nd 输出是:

Select the choices below
    1.Display Book
    2.Borrow Book
    3.Recieve Book

输入您的选择:2 输入要借的书名:pyton 回溯(最近一次调用最后一次): 文件“library_management.py”,第 45 行,在 chooice=input("你的意思是 %s"%get_close_matches(book,books)[0] ,"输入 Y 表示是 N 表示否") 类型错误:输入预计最多 1 个参数,得到 2

我不知道为什么我会遇到这个错误是我在某个地方搞砸了还是我错过了任何变量 plzz helo 我只是一个初学者,所以请帮助我

0 个答案:

没有答案
相关问题