20220328-day17:利用字典实现选择函数并执行功能


def run():
func_dict = {
'1': {'title': "第一部分", 'func': "page.execute"},
'2': {'title': "第二部份", 'func': "search.execute"},
'3': {'title': "第三部分", 'func': "download.execute"},
}
tips = ";".join(["{}.{}".format(k, v['title']) for k, v in func_dict.items()])
while True:
print(tips)
choice = input("请输入序号(Q/q退出)")
if choice.upper() == 'Q':
break
data_dict = func_dict.get(choice)
print(data_dict)
if not data_dict:
print(data_dict)
print("序号不存在,请重新输入!")
continue
print(data_dict['func'])#()