1. 程式人生 > 其它 >Python:呼叫內建函式

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')