# 有人能告诉我我做错了什么吗？ 它一直说 meal_cost is not defined

[英]Can someone tell me what im doing wrong? it keeps saying meal_cost is not defined

def solve(meal_cost, tip_percent, tax_percent):
meal_cost = float(input())
tip_percent = int(input())
tax_percent = int(input())

tip = meal_cost*tip_percent/100
tax = meal_cost*tax_percent/100
total_cost = meal_cost + tip + tax

print(round(total_cost))

solve(meal_cost, tip_percent, tax_percent)

When you call solve , you have not defined any of the parameters you pass.当您调用solve时，您还没有定义您传递的任何参数。 The solution is to define them:解决方案是定义它们：

def solve(meal_cost, tip_percent, tax_percent):
meal_cost = float(input())
tip_percent = int(input())
tax_percent = int(input())

tip = meal_cost*tip_percent/100
tax = meal_cost*tax_percent/100
total_cost = meal_cost + tip + tax

print(round(total_cost))

meal_cost = 3.0
tip_percentage = 0.19
tax_percent = 0.1
solve(meal_cost, tip_percent, tax_percent)

Note that this will overwrite the values passed in because you then ask to input the actual values.请注意，这将覆盖传入的值，因为您随后会要求input实际值。 You can do this instead:你可以这样做：

def solve(meal_cost, tip_percent, tax_percent):
tip = meal_cost*tip_percent/100
tax = meal_cost*tax_percent/100
total_cost = meal_cost + tip + tax

print(round(total_cost))

meal_cost = float(input())
tip_percent = int(input())
tax_percent = int(input())
solve(meal_cost, tip_percent, tax_percent)

as pointed out by Charles in the comment.正如查尔斯在评论中指出的那样。