在python中传递参数,缺少4个必需的位置参数?

时间:2017-11-13 03:42:05

标签: python function

我目前正在为一个类进行股票计算器项目,并且无法弄清楚如何将一个参数从一个函数传递给另一个函数。它不断给我一个错误类型calculateProfit() missing 4 required positional arguments

def main():
    CONTINUE = 'y'
    while CONTINUE == 'y' or CONTINUE == 'Y':
        getInfo()
        pricePerShare, numOfShares, commissionRate, shareSold = calculateProfit()
        commissionPercent, spentOnShare, spentOnCommission, totalShareSold, profit, eightPercent = displayResults()
    CONTINUE = input("Would you like to continue? (Y/N)")
    if (CONTINUE.lower() == "n"):
        quit

我错过了什么吗?

1 个答案:

答案 0 :(得分:1)

calculateProfit()必须像calculateProfit(a, b, c, d)一样被调用,其中abcd是参数。我不知道该论点应该是什么,但您的代码所做的是将calculateProfit()的结果分配给pricePerShare, numOfShares, commissionRate, shareSold

也许你有这样的事情calculateProfit(pricePerShare, numOfShares, commissionRate, shareSold)