函数取两个值,即消费税前的餐饮成本。 在使用消费税之前,饮料成本需要打30%的折扣。 食品和服务税(GST)需要加在餐饮成本中,GST设置为15%,这是我得到的答案,似乎我得到的答案是一样的,而不是11.5和17.02的单独答案。在
def dinner_calculator(meal_cost, drinks_cost):
""" Returns the total cost of the meal """
meal_cost = 1.15
drinks_cost = 1.30
return total_cost = meal_cost, drinks_cost
total_cost = dinner_calculator(10, 0)
print(round(total_cost, 2))
11.5
total_cost = dinner_calculator(12, 4)
print(round(total_cost, 2))
17.02
首先,
meal_cost = 15%
对Python没有任何意义。 当必须应用百分比计算时,请考虑改用系数:用这个系数乘以一个数,就可以算出这个数+15%。你也可以喝点酒。在
然后
^{pr2}$return total_cost = meal_cost, drinks_cost
试图返回赋值的结果,但这是错误的。 您要做的是直接返回值的结果或使用中间变量:
最后,请记住,通过执行
meal_cost, drinks_cost
操作,您只需生成一个元组,而不是一个加法。 你想要的可能是:最后,您可能应该查看一下Python 2或{a2}的官方Python教程
相关问题 更多 >
编程相关推荐