python:调用内置函数

问题描述:尝试下博客园如何上传GIF

 

# hzh 每天进步一点点
# 2022/5/13 17:24
import colorama
import time
import os
colorama.init(autoreset=True)
class rcolors:
    OKRED = '\033[1;31m'
    END = '\033[0m'

class Bcolors:
    OKRED = '\033[1;32m'
    END = '\033[0m'

dict_ticker = {'G1569':['北京南-天津南','18:05','18:39','00:34'],
               'G1567':['北京南-天津南','18:15','18:49','00:34'],
               'G8917':['北京南-天津西','18:20', '19:19', '00:59'],
               'G203':['北京南-天津南','18:35', '19:09', '00:34'],
               }
print(rcolors.OKRED+'车次\t\t出发站-到达站\t\t出发时间\t\t到达时间\t\t历时时长'+rcolors.OKRED)

for item in dict_ticker:
    print(Bcolors.OKRED+item,end=' ')
    for i in dict_ticker[item]:
        print(Bcolors.OKRED+i,end='\t\t')
    print()

def xunhuan():
    train_no = input('请输入要购买的车次:')
    persons = input('请输入乘车人,如果是多人请使用都好分隔:')
    flag = True
    for j in dict_ticker:  #输出字典的key,作为输入高铁班次做对比
            if train_no != j:
                flag = False
                #print('没有查询到该车次信息,请重新输入:')

            else:
                flag = True
                s = f'您已购买了{train_no}次列车,'
                s_info = dict_ticker[train_no]
                s += s_info[0] + '' + s_info[1] + '开,'   #获取列表中的对应索引的值
                print('正在查询余票.')
                time.sleep(2)
                print('正在出票中,请稍等...')
                time.sleep(3)
                print(Bcolors.OKRED + f'{s}请{persons}尽快取走纸质车票,祝您旅途平安。【铁路客服】' + Bcolors.END)
                break
    if not flag:
        print(rcolors.OKRED+'未查询到该车次信息,或者输入有误,请重新输入'+rcolors.END)
        xunhuan()
xunhuan()
os.system('pause')

 

posted @ 2022-05-13 22:12  我爱睡莲  阅读(58)  评论(0编辑  收藏  举报