Python構建跳轉表

def f1():
    print('You input 1')
def f2():
    print('You input 2')
def f3():
    print('You input 3')
funcDict = {'1':f1,
            '2':f2,
            '3':f3}
x = input('Input an integer to call different function:')
func = funcDict.get(x, None)
if func:
    func()
else:
    print('Wrong integer.')

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章