day13

# 作业要求:下述所有代码画图以及分析代码执行流程
# 1、以定义阶段为准,先画出名称空间的嵌套关系图
# 2、然后找到调用函数的位置,写出函数调用时代码的执行过程,涉及到名字的查找时,参照1中画好
#    的嵌套图,标明查找顺序,一层一层直到找到位置


# ===================题目一===================
input=333
def func():
    input=444
func()
print(input)

# ===================题目二===================
def func():
    print(x)
x=111

func()


# ===================题目三===================
x=1
def func():
   print(x)


def foo():
    x=222
    func()

foo()

# ===================题目四===================
input=111
def f1():
    def f2():
        # input=333
        print(input)
    input=222

    f2()

f1()

# ===================题目五===================
x=111
def func():
    print(x) #
    x=222

func()


# ===================题目六===================
x=111

def foo():
    print(x,)

def bar():
    print(x)

foo()
bar()

# ===================题目七===================
x=1
def func2():
    func1()

x=2
def func1():
    print(x)

x=3

func2()

# # ===================题目八===================
# 1、如下全局变量记录了当前登录用户,编写登录功能,一旦用户登录成功,则将全局变量赋值为当前登录的用户名
# login_user=None
def login():
    print('登录功能')
inp_name = input('请输入用户名:').strip()
pwd1 = input('请输入密码:'), strip()
inp_pwd = int(pwd1)
with open ('user.txt',mode ='r',encoding='utf-8') as f:
    for line in f:
        user =line.strip('\n').split(':')
        username,password =user
        if inp_name == username and inp_pwd ==password :
            print('登录成功')
        else:
            print('用户名或密码错误')
            login()

login()


# 2、针对之前编写的查询余额的功能,添加额外的逻辑:如果用户没有登录,则先执行登录功能

def login():
    print('登录功能')
def withdraw():
    print('提现功能')
def transfer():
    print('转账功能')
def recharge():
    print('充值功能')
func_dic={
    '1':[login,'登录'],
    '2':[withdraw,'提现'],
    '3':[transfer,'转账'],
    '4':[recharge,'充值']

}
while True:
    print('0    退出')
    for k in func_dic:
        print('%s    %s'%(k,func_dic[k][1]))
        # print("%s    %s" % (k, func_dic[k][1]))
    choice=input('请输入指令:')
    if choice=='0':
        break
    if choice in func_dic:
        #如果用户输入的是不是退出或登录,那要检查用户是否已登录
        if choice != '1':
            with open ('login_user.txt',mode='r',encoding='utf-8) as f1:
                if usename not in f :
                    print('请先登录账户'))
                    login()
                else:
                    func_dic[choice][0]
    else:
        print('指令错误')


你可能感兴趣的:(day13)