含税餐费计算

2024-05-12 20:27:00 发布

您现在位置:Python中文网/ 问答频道 /正文

很抱歉,有时我会为python的基础知识而挣扎。下面的代码不工作。在

def cost(c,r,t)
total cost = c*(1+r)*(1+t)
print total cost

cost(44.5, 6.75%, 15%)

我试图根据以下各项计算出总膳食成本:

^{pr2}$

Tags: 代码deftotal成本printcost我会膳食
2条回答

您的函数只需返回成本,而不必在内部打印出来。在

def cost(cost, rate, tip):
    return cost*(1+rate)*(1+tip)

print cost(44.5, 0.0675, 0.015)
def cost(c,r,t):
    total_cost = c*(1+r)*(1+t)
    print total_cost

cost(44.5, 6.75/100, 15/100)

百分号是Python中的一个特殊字符。替换%sign可解决语法错误。在

相关问题 更多 >