python使用循环实现以下功能:出租车计价 收费标准 3公里以内收费13元。 基本单价 23元公里 超出3公里以外。 空驶费超过15公里后每公里加收单价的50的空驶费即345元公里。 要求 输入公里数打印出费用金额以元为单位四舍五入。
distance = float(input("请输入行驶公里数:")) if distance <= 3: fee = 13 else: fee = 13 + (distance - 3) * 2.3 if distance > 15: fee += (distance - 15) * 2.3 * 0.5 # 空驶费 print("费用为:{}元".format(round(fee))) # 四舍五入保留整数元
原文地址: https://www.cveoy.top/t/topic/hpBm 著作权归作者所有。请勿转载和采集!