money_recharge()
from atm.lib_common.file_handle import * def money_recharge(username,money_recharge): """充值函数 """ user_pwd_money = file_r(r"F:\pylearn\atm\api\账户密码.txt") username_pwd=dict() username_list=list() username_money = dict() user_number=len(file_r(r"F:\pylearn\atm\api\账户密码.txt")) for i in range(len(file_r(r"F:\pylearn\atm\api\账户密码.txt"))): username_file = user_pwd_money[i].strip().split(":")[0] # 用户名 pwd_file = user_pwd_money[i].strip().split(":")[1] # 密码 money_file = user_pwd_money[i].strip().split(":")[2] # 余额 username_list.append(username_file)#用户名列表 username_money[username_file] = money_file#用户名和余额的字典 username_pwd[username_file]=pwd_file#用户名和密码的字典 print(f"尊敬的用户{username}您好,您的账户余额为{username_money[username]}") username_money[username]=str(money_recharge+int(username_money[username]))#余额更新 print(f"充值成功!您的账户余额为{username_money[username]}") file_w(r"F:\pylearn\atm\api\账户密码.txt","")#清空账户密码.txt for i in range(user_number):#写入更新后的用户名:密码:余额 file_a(r"F:\pylearn\atm\api\账户密码.txt", f"{username_list[i]}:{username_pwd[username_list[i]]}:{username_money[username_list[i]]}\n") return money_recharge("黄健",10000)
money_reduce()
from atm.lib_common.file_handle import * def money_reduce(username, money_reduce): """余额减少函数 """ user_pwd_money = file_r(r"F:\pylearn\atm\api\账户密码.txt") username_pwd = dict() username_list = list() username_money = dict() user_number = len(file_r(r"F:\pylearn\atm\api\账户密码.txt")) for i in range(len(file_r(r"F:\pylearn\atm\api\账户密码.txt"))): username_file = user_pwd_money[i].strip().split(":")[0] # 用户名 pwd_file = user_pwd_money[i].strip().split(":")[1] # 密码 money_file = user_pwd_money[i].strip().split(":")[2] # 余额 username_list.append(username_file) # 用户名列表 username_money[username_file] = money_file # 用户名和余额的字典 username_pwd[username_file] = pwd_file # 用户名和密码的字典 print(f"尊敬的用户{username}您好!您的账户余额为{username_money[username]}") username_money[username] = str(int(username_money[username])-money_reduce) # 余额更新 print("*"*120) print(f"购买成功!您的账户余额为{username_money[username]}") file_w(r"F:\pylearn\atm\api\账户密码.txt", "") # 清空账户密码.txt for i in range(user_number): # 写入更新后的用户名:密码:余额 file_a(r"F:\pylearn\atm\api\账户密码.txt", f"{username_list[i]}:{username_pwd[username_list[i]]}:{username_money[username_list[i]]}\n") return money_reduce("黄健", 1000)
标签:username,17,money,atm,pwd,file,txt From: https://www.cnblogs.com/yyyjw/p/17889124.html