主函数的写法

if __name__ == '__main__':
    msg = '''
       1:查询
       2:添加
       3:删除
       4:修改
       5:退出
       '''
    menu_dic = {

        '1': search,
        '2': add,
        '3': delete,
        '4': modify,
        '5': exit,
    }
    while True:
        print(msg)
        choice = input("操作>>: ").strip()
        if len(choice) == 0 or choice not in menu_dic:continue
        if choice == '5':break
        menu_dic[choice]()
原文地址:https://www.cnblogs.com/uglyliu/p/6030637.html