我想申请什么我已经了解的功能和参数,所以我想出了可以计算的学费(纯属假设)我的函数和参数代码有什么问题?
def renting_1(laptop, weeks):
laptop = 5 * weeks
if weeks > 10:
laptop -= 120
elif weeks > 5:
laptop -= 50
return laptop
def renting_2(textbooks, number_of_textbooks, weeks):
textbooks = number_of_textbooks * 20 + (10 * weeks)
if weeks >= 26:
textbooks -= (5 * (weeks - 26))
return textbooks
def school_cost(cost, weeks):
cost = 200 * weeks
return cost
def total_cost(weeks, number_of_textbooks):
return renting_1(weeks) + renting_2(number_of_textbooks, weeks) + school_cost(weeks)
print total_cost(22, 4)
,当我运行它,我收到此
代码Traceback (most recent call last):
File "python", line 22, in <module>
File "python", line 20, in total_cost
TypeError: renting_1() takes exactly 2 arguments (1 given)
有人可以解释,也许修复代码,所以我可以分析什么是错的?
为什么'laptop'的功能位置参数'renting_1'?它不应该在那里吗?因为你正在函数中重新定义'laptop'。 – abccd
你在这里给出了一个参数......'renting_1(weeks)'阅读错误。 –
对于您的函数'renting_1','renting_2'和'school_cost',您添加了第一个参数,该参数不应该在那里。从参数中分别删除'laptop','textbooks'和'cost'。这可能是一个错字,或者你不太理解论证如何工作。还要阅读错误信息,那个很清楚。 –