Python的if语句实现打车费用计算

问题描述:输入出租车类型和里程,计算打车费用。计算方式为:3公里以内8元;3公里以上,0型车每公里1.5元,1型车每公里2元。

#计程车计价系统
dist=float(input("请输入乘车距离(公里):"))
taxi=input("请输入车型(01.0号车型 02.1号车型):")

cost=0

if dist>3:
	if taxi=="01":
		cost=8+(dist-3)*1.5

	elif taxi=="02":
		cost=8+(dist-3)*2
	
	else:
		print("输入错误!")

elif dist<=3:
	cost=8



else:
	print("输入错误!")


print("您好,请支付:",cost,"元")

你可能感兴趣的:(Python的if语句实现打车费用计算)