运行以下代码似乎指示没有足够的参数传递给该类时,我收到以下错误:TypeError:addBook()缺少1个必需的位置参数:'cost'
我的目标是将标题,作者和费用存储在添加到列表中的单独变量中。我添加了下面两个程序的一部分,这给了我这个问题:
class book:
def __init__(self, title, author, cost, cashBalance, price, titleList, authorList, costList, priceList, sell):
self.title = title
self.author = author
self.cost = cost
self.cashBalance = 1000
self.price = price
self.titleList = []
self.authorList = []
self.costList = []
self.priceList = []
self.sell = sell
def addBook(self, title, author, cost):
price = round(cost * 1.1, 2)
self.titleList.append(title)
self.authorList.append(author)
self.costList.append(cost)
self.priceList.append(price)
下面是使用上面的类代码的程序部分:
from EBS_Class import book as b
play = True
while play == True:
decision = input('''Would you like to:
A) Add book
S) Sell book
R) Reduce book prices across board by 2%
I) Increase book prices across the board by 2%
V) Display inventory
W) Write inventory to a file
L) Load inventory from an existing file
Q) Quit ''')
if decision == "A":
title = input("What is the name of the book you want to add? ")
author = input("What is the name of the author of the book? ")
cost = float(input("What is the price of the book? "))
b.addBook(title, author, cost)