标签:break values bank log 错误 pca inf 登录 strip()
from interface import user,shopping,bank
from lib import common
def register():
while True:
print(‘注册‘)
inp_name=input(‘请输入用户名‘).strip()
pwd=input(‘请输入密码‘).strip()
pwd1=input(‘确认密码‘).strip()
if pwd==pwd1:
flag,msg=user.register_interface(inp_name,pwd)
print(msg)
break
else:
print(‘两次密码不一致‘)
user_info={
‘name‘:None
}
def login():
while True:
inp_name=input(‘请输入用户名‘)
pwd=input(‘请输入密码‘)
flag,msg=user.login_interface(inp_name,pwd)
if flag:
user_info[‘name‘]=inp_name
print(msg)
break
else:
print(msg)
@common.auth
def check_balance():
res=bank.check_balance_interface(user_info[‘name‘])
print(res)
@common.auth
def trancefer():
while True:
print(‘转账‘)
to_name=input(‘请输入对方账户‘)
money=input(‘请输入转账金额‘)
if money.isdigit():
money=int(money)
flag,msg=bank.trancefer_interface(user_info[‘name‘],to_name,money)
print(msg)
break
else:
print(‘请正确输入转账金额‘)
@common.auth
def repay():
while True:
print(‘还款‘)
money=input(‘请输入还款金额‘)
if money.isdigit():
money=int(money)
flag,msg=bank.repay_interface(user_info[‘name‘],money)
print(msg)
break
else:
print(‘错误输入‘)
@common.auth
def withdraw():
while True:
print(‘取款‘)
money=input(‘请输入取款金额‘)
if money.isdigit():
money=int(money)
flag,msg=bank.withdraw_interface(user_info[‘name‘],money)
if flag:
print(msg)
break
else:
print(msg)
else:
print(‘错误输入‘)
@common.auth
def check_bank_flow():
print(‘查看流水‘)
res=bank.flow_interface(user_info[‘name‘])
print(res)
@common.auth
def shop():
print(‘购物‘)
goods_list=[
[‘苹果‘,10],
[‘大米‘,90],
[‘白菜‘,5]
]
shop_dic={}
cost=0
while True:
for k,v in enumerate(goods_list):
print(‘商品编号%s--%s----商品价格%s rmb‘%(k,v[0],v[1]))
inp_num=input(‘请输入商品编号,按q结算并退出‘)
if inp_num.isdigit():
inp_num=int(inp_num)
if inp_num<len(goods_list):
if goods_list[inp_num][0] not in shop_dic:
shop_dic[goods_list[inp_num][0]]={‘price‘:goods_list[inp_num][1],‘num‘:1}
else:
shop_dic[goods_list[inp_num][0]][‘num‘]+=1
else:
print(‘商品编号不正确‘)
elif inp_num==‘q‘:
for item in shop_dic.values():
cost+=item[‘price‘]*item[‘num‘]
flag,msg=shopping.shopping_interface(user_info[‘name‘],cost,shop_dic)
if flag:
print(msg)
return
else:
print(msg)
return
else:
print(‘输入错误‘)
@common.auth
def check_shopping_car():
print(‘查看购物车‘)
res=shopping.check_shopcar(user_info[‘name‘])
print(res)
func_dic = {
‘1‘:register,
‘2‘:login,
‘3‘:check_balance,
‘4‘:trancefer,
‘5‘:repay,
‘6‘:withdraw,
‘7‘:check_bank_flow,
‘8‘:shop,
‘9‘:check_shopping_car
}
def run():
msg=‘‘‘
1.注册
2.登录
3.查看余额
4.转账
5.还款
6.取款
7.查看流水
8.购物
9.查看购物车
‘‘‘
while True:
print(msg)
inp=input(‘请选择功能‘)
if inp not in func_dic:
print(‘选择错误‘)
continue
func_dic[inp]()
标签:break values bank log 错误 pca inf 登录 strip()
原文地址:https://www.cnblogs.com/fushaunglin/p/9484494.html