我试图输出300.00作为我在python中的租车项目的基本费用,但使用的是codio。300.0是我收到的以下代码的结果,我遗漏了什么??在
baseCharge = 0
if rentalCode == "B":[enter image description here][1]
baseCharge = (rentalPeriod) * (budgetCharge)
elif rentalCode == "D":
baseCharge = float(rentalPeriod) * float(dailyCharge)
elif rentalCode == "W":
baseCharge = float(rentalPeriod) * float(weeklyCharge)
print(baseCharge)
最后一次运行时间:2019年1月28日上午9:37:55 检查1失败 输出: (B) udget,(每天)还是(W)每周出租? 租赁天数: D 5 300 预期: (B) udget,(每天)还是(W)每周出租? 租赁天数: D 5 300.00美元
您需要输入:
print("{0:.2f}".format(baseCharge))
为了让Python以两位数输出浮点值。在
基本上在baseCharge
print
命令前面添加("{0:.2f}".format)
。在相关问题 更多 >
编程相关推荐