# 今日作业:
# 1、函数对象优化多分支if的代码练熟
# def loing():
# print("登录")
# def top_up():
# print("充值")
# def registereg():
# print("注册")
# def transfer():
# print("转账")
# # while True:
# # print("""
# # 0: 退出
# # 1:充值
# # 2:注册
# # 3:转账
# # 4:登录
# # """)
# # chions=input("请输入你的选择").strip()
# # if not chions.isdigit():
# # print("请输入数字哦")
# # continue
# # if chions=="0":
# # break
# # elif chions=="1":
# # top_up()
# #
# # elif chions=="2":
# # registereg()
# # elif chions== "3":
# # transfer()
# # elif chions=="4":
# # loing()
# # else:
# # print("命令不存在")
#
# # 修正:
# name_dict={ "0":['退出',None],
# "1":['充值',top_up],
# "2":['注册',registereg],
# "3":['转账',transfer],
# "4":['登录',loing]}
# while True:
# for k in name_dict:
# print(k,name_dict[k][0])
# chions=input("请输入你的选择").strip()
# if not chions.isdigit():
# print("请输入数字哦")
# continue
# if chions=="0":
# break
# if chions in name_dict: #记得判断是否在字典里在进行
# name_dict[chions][1]()
# else:
# print("命令不存在")
# # 更优化
# 2、编写计数器功能,要求调用一次在原有的基础上加一
# # 温馨提示:
# I:需要用到的知识点:闭包函数+nonlocal
# II:核心功能如下:
def func():
x=0
def counter():
nonlocal x
x+=1
return x
return counter
couter=func()
print(couter()) # 1
print(couter()) #
print(couter()) # 3 2
print(couter()) # 4
print(couter()) # 5