[英]Can someone tell me what im doing wrong? it keeps saying meal_cost is not defined
def solve(meal_cost, tip_percent, tax_percent):
# Write your code here
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):
# Write your code here
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.正如查尔斯在评论中指出的那样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.