# ===================题目一===================
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=333
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():
inp_user = input('用户名:').strip()
inp_pwd = input('密码:').strip()
if inp_user == 'qqq' and inp_pwd == '123':
print("登录成功")
global login_user
login_user = inp_user
else:
print("登录失败")
login()
print(login_user)
2、针对之前编写的查询余额的功能,添加额外的逻辑:如果用户没有登录,则先执行登录功能
login_user = None
def login():
inp_user = input('用户名:').strip()
inp_pwd = input('密码:').strip()
if inp_user == 'qqq' and inp_pwd == '123':
print("登录成功")
global login_user
login_user = inp_user
else:
print("登录失败")
def balance(login_user):
if login_user is None:
print("请先登录")
login()
else:
with open('b.txt', 'rt', encoding='utf-8')as f:
for i in f:
name, money = i.strip().split(':')
if login_user == name:
print('您的余额为:{}'.format(money))
break