我不明白这个错误消息 (Python)
I don't understand this error message (Python)
我刚刚开始 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'
方法receiptCalculation
需要参数:PriceOfMeal
和TipAmount
。 receiptCalculation(PriceOfMeal)
只向该方法传递一个参数,因此会引发错误。
receiptCalculation
接受两个参数,但在线:
print(receiptCalculation(PriceOfMeal))
只给出了一个参数。因此,解释器告诉您,您在函数调用中恰好缺少一个参数。
我刚刚开始 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'
方法receiptCalculation
需要参数:PriceOfMeal
和TipAmount
。 receiptCalculation(PriceOfMeal)
只向该方法传递一个参数,因此会引发错误。
receiptCalculation
接受两个参数,但在线:
print(receiptCalculation(PriceOfMeal))
只给出了一个参数。因此,解释器告诉您,您在函数调用中恰好缺少一个参数。