# 1、函数对象优化多分支if的代码练熟
# def login():
# print('登录功能:')
#
# def transfer():
# print('转账功能:')
#
# def check_balance():
# print('查询余额:')
#
# def withdrow():
# print('提现:')
#
#
# func_dic={
# '0':['退出',None],
# '1':['登录',login],
# '2':['转账',transfer],
# '3':['查询',check_balance],
# '4':['提现',withdrow]
# }
#
# while True:
# for k in func_dic:
# print(k,func_dic[k][0])
#
#
# choice = input('请输入命令编号:').strip()
#
# if not choice.isdigit():
# print('请输入数字!')
# continue
#
# if choice == '0':
# print('退出成功!')
# break
#
# if choice in func_dic:
# func_dic[choice][1]()
#
# else:
# print('输入的命令不存在!')
'''
2、编写计数器功能,要求调用一次在原有的基础上加一
温馨提示:
I:需要用到的知识点:闭包函数+nonlocal
II:核心功能如下:
def counter():
x+=1
return x
要求最终效果类似
print(couter()) # 1
print(couter()) # 2
print(couter()) # 3
print(couter()) # 4
print(couter()) # 5
'''
def outer():
x=0
def counter():
nonlocal x
x += 1
return x
return counter
counter=outer()
print(counter())
print(counter())
print(counter())