pythonbook/Python 基础教程/1.5.7 F综合练习6.py

69 lines
3.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 1.地铁站编号和站名对应关系如下: 1=朱辛庄 2=育知路 3=平西府 4=回龙观东大街 5=霍营 //....
#
# 遍历打印(可以不按顺序打印) 第10站: 森林公园南门 第6站: 育新 第12站: 奥体中心 第13站: 北土城 //...
#
# 2.计算地铁票价规则: 总行程 3站内包含3站收费3元 3站以上但不超过5站包含5站的收费4元 5站以上的在4元的基础上每多1站增加2元 10元封顶
#
# 3.打印格式(需要对键盘录入的上车站和到达站进行判断,如果没有该站,提示重新输入,直到站名存在为止): 注意每站需要2分钟 请输入上车站: 沙河 您输入的上车站:沙河不存在,请重新输入上车站: 上地 您输入的上车站:上地不存在,请重新输入上车站: 朱辛庄 请输入到达站: 沙河 您输入的到达站:沙河不存在,请重新输入到达站: 西二旗 您输入的到达站:西二旗不存在,请重新输入到达站: 西小口 从朱辛庄到西小口共经过6站收费6元大约需要 12分钟
st = """十三号街站 05:30 23:00 —— ——
中央大街站 05:31 23:01 06:28 23:47
七号街站 05:33 23:03 06:26 23:45
四号街站 05:36 23:06 06:24 23:42
张士站 05:38 23:08 06:21 23:40
开发大道站 05:41 23:11 06:19 23:37
于洪广场站 05:43 23:13 06:16 23:35
迎宾路站 05:46 23:16 06:14 23:33
重工街站 05:48 23:18 06:11 23:30
启工街站 05:51 23:21 06:09 23:28
保工街站 05:53 23:23 06:07 23:26
铁西广场站 05:55 23:25 06:04 23:23
云峰北街站 05:58 23:28 06:02 23:21
沈阳站 06:01 23:31 06:00 23:18
太原街站 06:03 23:33 06:16 23:16
南市场站 06:05 23:35 06:13 23:13
青年大街站 06:07 23:37 06:11 23:11
怀远门站 06:10 23:40 06:09 23:09
中街站 06:13 23:43 06:06 23:06
东中街站 06:15 23:45 06:04 23:04
滂江街站 06:17 23:47 06:01 23:01
黎明广场站 —— —— 06:00 23:00"""
lst = st.split()
llsstt = list(filter(lambda x : '' in x,lst))
print(llsstt)
while True:
upstation = input('请输入上车站:')
if upstation not in llsstt:
print(f'您输入的上车站:{upstation}不存在,请重新输入上车站')
upstation_idx = llsstt.index(upstation)
downstation = input('请输入下车站:')
if downstation not in llsstt:
print(f'您输入的下车站:{upstation}不存在,请重新输入下车站')
else:
downstation_idx = llsstt.index(downstation)
if downstation_idx < upstation_idx:
print('下车站必须在上车站之后')
else:
break
diff = downstation_idx - upstation_idx
price = 0
if diff <= 3:
price = 3
elif diff <= 5:
price = 4
else:
price = 4 + (diff - 5)*2
if price > 10:
price = 10
print(f'{upstation}{downstation}共经过{diff}站收费{price}元,大约需要{diff*2}分钟')