我刚刚开始使用Python,我编写了这个小程序,它应该接受用户输入并打印结果。但是,我不了解运行时发生的错误:
代码:
# The purpose of this program is to use the user's input (the price of their meal), and outputs a receipt telling them how much the meal costs with tax and an optional tip.
print("Thank you for coming! We hoped you enjoyed the meal. Please use our all new PythonBillPayer! A fast way to pay for your day!")
PriceOfMeal = float(input("Please enter the price of your meal"))
TipAmount = float(input("Please enter amount of tip you would like to give"))
def receiptCalculation(PriceOfMeal, TipAmount):
NewPrice = (((((13/100)*PriceOfMeal)) + PriceOfMeal) + TipAmount)
return NewPrice
print(receiptCalculation(PriceOfMeal))
错误消息:
builtins.TypeError: receiptCalculation() missing 1 required positional argument: 'TipAmount'
答案 0 :(得分:0)
方法receiptCalculation
需要参数:PriceOfMeal
和 TipAmount
。 receiptCalculation(PriceOfMeal)
只向该方法传递一个参数,因此会引发错误。
答案 1 :(得分:0)
receiptCalculation
有两个参数,但在线:
print(receiptCalculation(PriceOfMeal))
只给出了一个论点。所以解释器告诉你,你在函数调用中只缺少一个参数。