[英]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
需要Arguments: PriceOfMeal
和TipAmount
。 receiptCalculation(PriceOfMeal)
只向該方法傳遞一個參數,因此它會引發一個錯誤。
receiptCalculation
需要兩個參數,但就行了:
print(receiptCalculation(PriceOfMeal))
僅給出一個論點。 所以解釋器告訴你你在函數調用中缺少一個參數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.