某城市出租车计费标准如下:
(1)起步里程为3公里(含3公里),起步费13元;
(2)载客里程3~15公里范围的,除起步费外,超过3公里的部分按基本单价2.3元/公里计算;
(3)载客里程超过15公里的,15公里内的按照(2)计算,超过15公里的基本单价加收50%的费用;
(4)时速低于12公里/小时的慢速行驶时间计入等待时间,每等待1分钟加收1元;
请输入乘车里程(整数)、等待时间,输出车费。
s=int(input('请输入乘车里数:'))
t=float(input('请输入等待时间:'))
if 0<s<=3:
f=13+t
print("车费为:{}".format(f))
elif 3<s<=15:
f=13+(s-3)*2.3+t
print("车费为:{}".format(f))
else:
f=13+(15-3)*2.3+(s-15)*2.3*1.5+t
print("车费为:{}".format(f))
结果:
请输入乘车里数:10
请输入等待时间:0
车费为:29.099999999999998
不知该如何改正?
s = int(input('请输入乘车里数:'))
t = float(input('请输入等待时间:'))
if 0 < s <= 3:
f = 13 + t
elif 3 < s <= 15:
f = 13 + (s - 3) * 2.3 + t
else:
f = 13 + (15 - 3) * 2.3 + (s - 15) * 2.3 * 1.5 + t
# round(浮点数,保留小数位数) 保留方式,四舍五入
print("车费为:{}".format(round(f,3)))
有帮助请点一下右上角的采纳,谢谢
```
s=int(input('请输入乘车里数:'))
t=float(input('请输入等待时间:'))
if 0<s<=3:
f=13+t
print("车费为:%.1f"%f)
elif 3<s<=15:
f=13+(s-3)*2.3+t
print("车费为:%.1f"%f)
else:
f=13+(15-3)*2.3+(s-15)2.31.5+t
print("车费为:%.1f"%f)
```上面这个代码,你可以试试。保留了一位小数。
这个链接有详细的解释: https://blog.csdn.net/weixin_39818014/article/details/114943743?utm_medium=distribute.wap_aggpage_search_result.none-task-blog-2~aggregatepage~first_rank_ecpm_v1~rank_v31_ecpm-1-114943743.wap_agg_so&utm_term=python%E6%B5%AE%E7%82%B9%E6%95%B0%E6%9C%89%E5%87%A0%E7%A7%8D%E8%A1%A8%E7%A4%BA%E6%96%B9%E6%B3%95
希望对你有帮助~