提问人:Zoo1E Z 提问时间:11/15/2023 最后编辑:Zoo1E Z 更新时间:11/15/2023 访问量:28
value 不能使用 class [closed] 放入列表中
value can't put in the list using class [closed]
问:
[book.py]
from book_info import book_lists
class Book:
def __init__(self, books):
self.books = books
def book_manag(self):
want_book = []
while True:
answer = input("Do you wanna borrow or return or no? (borrow/return/no) :")
# split the cases
if answer == "no":
break
elif answer == "borrow":
bo_want_book = input("which books do you wanna borrow?:")
want_book.append(bo_want_book)
for book in book_lists:
if bo_want_book == book['title']:
book["status"] = "borrowed"
elif answer == "return":
re_want_book = input("which books do you wanna return?:")
for book in book_lists:
if re_want_book == book["ti`your text`tle"]:
book["status"] = "available"
return want_book
book_m = Book(book_lists) # define class
print("\n")
for i in book_lists:
print(i)
book_lists = book_m.book_manag()
print(f"final book Lists : {book_lists}")
[book_info]
book_lists = [{"title":"harry poter",
"author" : "amy block",
"ISBN" : "34567890",
"status" : "available"},
{"title": "hunger game",
"author": "casy",
"ISBN": "456787678",
"status": "available"},
{"title": "To Kill a Mockingbird",
"author": "Harper Lee",
"ISBN": "978-0-06-112008-4",
"status": "available"},
{"title": "1984",
"author": "George Orwell",
"ISBN": "978-0-452-28423-4",
"status": "available"},
{"title": "The Great Gatsby",
"author": "F. Scott Fitzgerald",
"ISBN": "978-0-7432-7356-5",
"status": "available"},
{"title": "Pride and Prejudice",
"author": "Jane Austen",
"ISBN": "978-1-85326-120-9",
"status": "available"},
{"title": "The Catcher in the Rye", "author": "J.D. Salinger", "ISBN": "978-0-316-76948-7",
"status": "available"},
{"title": "The Hobbit", "author": "J.R.R. Tolkien", "ISBN": "978-0-261-10280-2",
"status": "available"},
{"title": "The Alchemist", "author": "Paulo Coelho",
"ISBN": "978-0-06-112241-5", "status": "available"},
{"title": "The Hunger Games",
"author": "Suzanne Collins", "ISBN": "978-0-439-02348-1", "status": "available"},
{"title": "The Girl with the Dragon Tattoo",
"author": "Stieg Larsson", "ISBN": "978-0-307-26995-8", "status": "available"},
{"title": "Harry Potter and the Sorcerer's Stone",
"author": "J.K. Rowling", "ISBN": "978-0-545-01022-6", "status": "available"}
]
[customer.py]
from book import Book
from book_info import book_lists
book_m = Book(book_lists)
value = book_m.book_manag()
print(f"Books borrowed: {value}")
[说明] 在这种情况下,“值”是 [](我的意思是空的) 我想我应该得到一些字符串值(当我在“book.py”中借用并输入“哈利波特”时) 为什么。。。它是空的 我将“customer.py”连接到“book.py”。
结果是
“借阅的书籍:[]”
我不知道为什么这个结果总是空列表
我声明“return want_book”,所以我想我应该得到这部分的值 [value = book_m.book_manag()
print(f“借阅的书籍:{value}”)]
我说得对吗?
答: 暂无答案
评论
book_manag