购买地铁车票的规定如下:
乘 1~4 站,3 元/位;
乘 5~9 站,4 元/位;
乘 9 站以上,5 元/位。
请用程序实现
输入乘坐人数per_num和乘坐站数sta_num,计算购买地铁车票需要的总金额,并将计算结果输出。
注意: 如果「乘坐人数」和「乘坐站数」为0或负数,输出error。
# 请使用 input() 输入乘坐的人数 per_num 和站数 sta_num
per_num=int(input())
sta_num=int(input())
# 请判断输入的人数和站数是否正确,计算购买车票的总金额,并将计算结果输出
if per_num<=0 or sta_num<=0:
print("error")
else:
if 1<=sta_num<=4:
pm=3
if 5<=sta_num<=9:
pm=4
if sta_num>9:
pm=5
count=pm*per_num
print(count)
最后
以上就是会撒娇月光最近收集整理的关于Python地铁车票的全部内容,更多相关Python地铁车票内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复