扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
今天就跟大家聊聊有关使用python怎么编写一个银行账户系统,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
创新互联建站是一家专业提供灵台企业网站建设,专注与成都网站建设、网站建设、成都h5网站建设、小程序制作等业务。10年已为灵台众多企业、政府机构等服务。创新互联专业网络公司优惠进行中。Python是一种编程语言,内置了许多有效的工具,Python几乎无所不能,该语言通俗易懂、容易入门、功能强大,在许多领域中都有广泛的应用,例如最热门的大数据分析,人工智能,Web开发等。
import math import re def main(): # 主函数 select = True while (select): menu() start_int = input("请选择你您想要操作功能的序号:") if start_int == "12": select = False print("你已经退出系统欢迎下次在来") elif start_int == "4": insert() elif start_int == "5": login() elif start_int == "6": show() elif start_int == "11": delete() elif start_int == "7": revise() elif start_int == "8": deposit() elif start_int == "9": getMoney() elif start_int == "10": UseMoney() def menu(): # 菜单显示 print("1========银行存取钱系统========") print("2===========================") print("3===========功能菜单===========") print("4=========注册个人信息==========") print("5============登入=============") print("6=========查询个人信息==========") print("7=========修改个人账户==========") print("8============存钱=============") print("9============取钱=============") print("10=========显示年收益==========") print("11========注销个人信息==========") print("12===========退出=============") filename = "Bank.txt" # 定义保存用户信息的文件名 def save(Bank): # 创建文件方法 try: Bank_txt = open(filename, "a") except Exception as e: Bank_txt = open(filename, "w") for info in Bank: Bank_txt.write(str(info) + "\n") Bank_txt.close() def insert(): # 注册方法 BankList = [] # 保存用户信息列表 mark = True # 是否继续添加 while mark: id = input("请输入您的ID密码(如1001):") if not id: break name = input("请输入姓名") if not name: break try: deposit = int(input("输入你要存款的金额")) if deposit == 0: break except: print("输入无效,不是输入整型数,请重新输入") continue Bank = {"id": id, "name": name, "deposit": deposit} BankList.append(Bank) mark = False save(BankList) print("注册成功") global g_select g_select = 0 global Username global Userpassword def login(): # 登入方法 global Username global g_select global g_BankQuery global Userpassword g_BankQuery = [] Username = str(input("请输入您的用户名")) Userpassword = str(input("请输入您的密码")) file = open(filename, 'r') Bank = file.readlines() # 读取全部内容 for list in Bank: d = dict(eval(list)) # 字符转化为字典 if d['name'] == Username and d['id'] == Userpassword: g_BankQuery.append(d) print("登入成功!") g_select = 1 else: pass if not g_BankQuery: g_select = 0 print("登入失败请先注册!") else: pass def show(): # 查询个人信息 if g_select == 1: format_title = "{:^6}{:^12}" print(format_title.format("名字", "存款")) format_date = "{:^6}{:^12}" for info in g_BankQuery: print(format_date.format(str(info.get('name')), str(info.get('deposit')))) else: print("请先登入!") def delete(): # 删除个人账户方法 global g_BankQuery cz = [] global g_select choose = 0 if g_select == 1: while choose < 3: username = str(input("请输入你姓名")) userpassword = str(input("请输入您的密码")) file = open(filename, 'r') Bank = file.readlines() # 读取全部内容 for list in Bank: d = dict(eval(list)) # 字符转化为字典 if d['name'] == username and d['id'] == userpassword: cz.append(d) file.close() choose = 3 NewBank = open(filename, 'w') # 以写的方式打开文件 for list2 in Bank: d2 = dict(eval(list2)) # 字符转化为字典 if d2['name'] != username and d2['id'] != userpassword: NewBank.write(str(d2) + "\n") else: pass else: pass if not cz: choose = choose + 1 if choose == 3: g_select = 0 print("请重新登入!") else: print("用户名或者密码错误,请重新输入你还有:" + str(3 - choose) + "机会") else: g_BankQuery.clear() g_select = 0 print("您的个人信息已经注销") else: print("请先登入!") def revise(): # 修改个人账户方法 cz = [] global g_select if g_select == 1: username = input("请输入您的用户名:") userpassword = input("请输入您的密码:") file = open(filename, 'r') Bank = file.readlines() # 读取全部内容 for list in Bank: d = dict(eval(list)) # 字符转化为字典 if d['name'] == username and d['id'] == userpassword: cz.append(d) file.close() NewBank = open(filename, 'w') # 以写的方式打开文件 for list2 in Bank: d2 = dict(eval(list2)) # 字符转化为字典 if d2['name'] == username and d2['id'] == userpassword: d2['name'] = input("输入您的新名字:") d2['id'] = input("输入您的新密码:") NewBank.write(str(d2) + "\n") print("修改成功,请重新登入!") g_select = 0 else: NewBank.write(str(d2) + "\n") else: pass if not cz: print("你输入的密码或者用户名有误请重新登入") g_select = 0 else: pass else: print("请先登入!") def deposit(): # 存钱方法 global g_BankQuery global g_select cz = [] if g_select == 1: money = int(input("请输入你要存多少钱:")) file = open(filename, 'r') Bank = file.readlines() # 读取全部内容 for list in Bank: d = dict(eval(list)) # 字符转化为字典 if d['name'] == Username and d['id'] == Userpassword: cz.append(d) file.close() NewBank = open(filename, 'w') # 以写的方式打开文件 for list2 in Bank: d2 = dict(eval(list2)) # 字符转化为字典 if d2['name'] == Username and d2['id'] == Userpassword: d2['deposit'] = str(int(d2['deposit']) + money) NewBank.write(str(d2) + "\n") print("储存成功!") g_BankQuery.clear() g_BankQuery.append(d2) else: NewBank.write(str(d2) + "\n") else: pass else: print("请先登入!") def getMoney(): # 取钱方法 global g_select global g_BankQuery cz = [] if g_select == 1: money = int(input("请输入你要取多少钱:")) file = open(filename, 'r') Bank = file.readlines() # 读取全部内容 for list in Bank: d = dict(eval(list)) # 字符转化为字典 if d['name'] == Username and d['id'] == Userpassword: cz.append(d) if money > int(d['deposit']): print("您的余额不足") else: file.close() NewBank = open(filename, 'w') # 以写的方式打开文件 for list2 in Bank: d2 = dict(eval(list2)) # 字符转化为字典 if d2['name'] == Username and d2['id'] == Userpassword: d2['deposit'] = str(int(d2['deposit']) - money) NewBank.write(str(d2) + "\n") print("取钱成功!") g_BankQuery.clear() g_BankQuery.append(d2) else: NewBank.write(str(d2) + "\n") else: pass else: print("请先登入!") def UseMoney(): # 利息计算 UM = True while UM: try: money = float(input("请输入你要投资理财多少钱:")) year = int(input("请你输入你要储存多少年:")) except: print("请你输入整数年份!") if 0 < year <= 3: profitmargin = 0.03 elif 3 < year <= 5: profitmargin = 0.04 elif 5 < year <= 10: profitmargin = 0.06 elif year > 10: profitmargin = 0.08 if money < 0 or year <= 0: print("您的本金不能少于0元或者年份不能少于0年") else: UM = False profit = round(money * year * profitmargin, 3) print("你储存:" + str(year) + "年将获得的利润会等于:" + str(profit) + "元本金加利润会等于:" + str(profit + money) + "元") if __name__ =="__main__":
运行图片:
看完上述内容,你们对使用python怎么编写一个银行账户系统有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注创新互联行业资讯频道,感谢大家的支持。
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流