#代码功能(1.用户登录三次验证,三次输错密码会被锁定300秒) #注册,取款,存款,查询,转账,购物车功能 #支付功能有余额支付,信用卡支付,组合支付 import time db_file_baihu = r"D:\360MoveData\Users\11419\Desktop\baihu.txt" db_file_heihu = r"D:\360MoveData\Users\11419\Desktop\heihu.txt" tag=True def chaxun(name,dic_baihu): user_name=name[0] print( """ ---------------------------- 账户名: %s 余额: %s 信用卡额度:%s 1.打印 2.返回上一层 ---------------------------- """ %(user_name,dic_baihu[user_name]["money"],dic_baihu[user_name]["xyk"])) choice = input("请选择") if choice == "1": print("打印成功,退回上一层") def zhuce(name,dic_baihu): global tag while tag: pwd=input("请输入密码纯六位数字: ") if not pwd.isdigit():continue if len(pwd) !=6:continue else: pwd2=input("请再次输入密码: ") if pwd == pwd2: while tag: money = input("请输入存款数字: ") if not money.isdigit() :continue xyk = input("请输入信用卡余额数字: ") if not xyk.isdigit(): continue print("正在注册中,请稍后........") time.sleep(2) dic_baihu[name]={ 'pwd': pwd2, 'money': money, 'xyk': xyk, 'count': '0' } jieguo=db_xie(dic_baihu) if jieguo == True: print(""" 注册成功 账户:%s 密码:%s 余额:%s 信用卡:%s """ %(name,pwd2,money,xyk)) tag = False else: print("注册失败") else: print("两次密码不一致") continue def zhuanzhang(name,*args): global tag user_name=name[0] dic_baihu=args[0] dic_heihu=args[1] dic_hu={} while tag: name2=input("请输入你要转给谁: ") if name2 not in dic_baihu and name2 not in dic_heihu: print(""" 该用户不存在 1.继续转账 2.退出 """) choice=input("请选择: ") if choice == "1": continue elif choice =="2": tag=False else: print("输入不正确") continue else: if name2 in dic_baihu: print("%s的余额为%s" %(user_name,dic_baihu[user_name]["money"])) while tag: mony1=input("请输入你要转多少:") if mony1.isdigit(): dic_hu[name2]={'pwd': dic_baihu[name2]["pwd"], 'money': int(dic_baihu[name2]["money"])+int(mony1), 'xyk': dic_baihu[name2]["xyk"], 'count': '0'} dic_hu[user_name]={'pwd': dic_baihu[user_name]["pwd"], 'money': int(dic_baihu[user_name]["money"])-int(mony1), 'xyk': dic_baihu[user_name]["xyk"], 'count': '0'} dic_baihu.update(dic_hu) print("转账中.......") time.sleep(2) jieguo=db_xie(dic_baihu) if jieguo == True: print("转账成功") tag = False else: print("转账失败") else: print("输入不正确,请重新输入") continue else: print("%s的余额为%s" % (user_name, dic_baihu[user_name]["money"])) while tag: mony1 = input("请输入你要转多少:") if mony1.isdigit(): dic_hu[name2] = {'pwd': dic_heihu[name2]["pwd"], 'money': int(dic_heihu[name2]["money"]) + int(mony1), 'xyk': dic_heihu[name2]["xyk"], 'count': '0'} dic_heihu.update(dic_hu) dic_hu.clear() dic_hu[user_name] = {'pwd': dic_baihu[user_name]["pwd"], 'money': int(dic_baihu[user_name]["money"]) - int(mony1), 'xyk': dic_baihu[user_name]["xyk"], 'count': '0'} dic_baihu.update(dic_hu) print("转账中.......") time.sleep(2) jieguo = db_xie(dic_baihu,dic_heihu) if jieguo == True: print("转账成功") tag=False else: print("转账失败") else: print("输入不正确,请重新输入") continue def cunkuan(name,dic_baihu): global tag user_name=name[0] dic1={} while tag: money1=input("请输入你要存多少钱: ") if money1.isdigit(): dic1[user_name]= {'pwd': dic_baihu[user_name]["pwd"], 'money': int(dic_baihu[user_name]["money"])+int(money1), 'xyk': dic_baihu[user_name]["xyk"], 'count': '0'} dic_baihu.update(dic1) jieguo=db_xie(dic_baihu) print("正在查询信息......") time.sleep(2) print("正在更新信息.......") if jieguo == True: print("存款成功,重新登陆查看") tag = False else: print("存款失败") else: print("输入不正确,输入存款的金额数字") def qukuan(name,dic_baihu): global tag user_name = name[0] dic1 = {} while tag: money1 = input("请输入你要取多少钱: ") if money1.isdigit(): if int(dic_baihu[user_name]["money"]) - int(money1) >=0: dic1[user_name] = {'pwd': dic_baihu[user_name]["pwd"], 'money': int(dic_baihu[user_name]["money"]) - int(money1), 'xyk': dic_baihu[user_name]["xyk"], 'count': '0'} dic_baihu.update(dic1) jieguo = db_xie(dic_baihu) print("正在查询信息......") time.sleep(2) print("正在更新信息.......") if jieguo == True: print("取款成功,重新登陆查看") tag = False else: print("取款失败") else: print("您账户目前余额为%s,余额不足" %dic_baihu[user_name]["money"]) else: print("输入不正确,输入存款的金额数字") def loging(dic_baihu,dic_heihu): global tag cishu=1 dic_baihu2={} dic_heihu2={} while tag: user_name = input("请输入登录名: ") if user_name not in dic_baihu and user_name not in dic_heihu: print(""" 该用户不存在!!! 1.注册 2.退出 """) choice=input("选择") if choice == "1": zhuce(user_name,dic_baihu) elif choice == "2": tag = False else: print("您输入的不正确,请重新输入") else: if user_name in dic_baihu: while tag: user_pwd = input("请输入密码: ") if user_pwd == dic_baihu[user_name]["pwd"]: print("登录成功") return True,user_name, else: if cishu > 1: print("您的账户已经被锁定") now_time=time.time() dic_baihu2[user_name]={"pwd":dic_baihu[user_name]["pwd"], "money":dic_baihu[user_name]["money"], "xyk":dic_baihu[user_name]["xyk"], "count":now_time} dic_heihu.update(dic_baihu2) dic_baihu.pop(user_name) db_xie(dic_baihu,dic_heihu) tag = False else: print("您输入的不正确,请重新输入") cishu+=1 else: if user_name in dic_heihu: coumputer_time=time.time() now_h_time=float(coumputer_time)-float(dic_heihu[user_name]["count"]) while tag: if now_h_time > 300: h_pwd=input("请输入密码: ") if h_pwd == dic_heihu[user_name]["pwd"]: dic_heihu2[user_name] = { "pwd": dic_heihu[user_name]["pwd"], "money": dic_heihu[user_name]["money"], "xyk": dic_heihu[user_name]["xyk"], "count":"0" } dic_baihu.update(dic_heihu2) dic_heihu.pop(user_name) db_xie(dic_baihu,dic_heihu) return True,user_name,dic_baihu else: if cishu > 2: print("%s输错密码太多次,已经被锁定" % user_name) dic_heihu2[user_name] = { "pwd": dic_heihu[user_name]["pwd"], "money": dic_heihu[user_name]["money"], "xyk": dic_heihu[user_name]["xyk"], "count": coumputer_time } dic_heihu.update(dic_heihu2) db_xie(dic_heihu) tag = False else: print("您输入的不正确,请重新输入") cishu +=1 else: print("%s 已经被锁定" %user_name) tag = False return user_name def shope(name,dic_baihu): global tag user_name=name[0] shope_car1 = {} tag = True while tag: print(""" 1.iphone xs max 10000 2.iphone xr 9000 3.iphone x 6000 4.mac 12000 5.结算 6.退出 """) choice = int(input("请选择要购买的商品: ")) if choice in [1, 2, 3, 4]: number = input("请输入你要购买的数量: ") if choice == 1: shope_car1["iphone xs max"] = {"price": 10000, "number": number} elif choice == 2: shope_car1["iphone xr"] = {"price": 9000, "number": number} elif choice == 3: shope_car1["iphone x"] = {"price": 6000, "number": number} elif choice == 4: shope_car1["mac"] = {"price": 12000, "number": number} else: if choice == 5: jiesuan(user_name,dic_baihu,shope_car1) elif choice == 6: tag = False else: print("请输入1-6") def xinyongka(name,dic_baihu): print("正在开发......") def jiesuan(name,*args): global tag,dic_baihu l=[] l1=[] dic={} dic_baihu={} shop_car={} dic_baihu.update(args[0]) shop_car.update(args[1]) sum_money2 = 0 if len(shop_car)>1: for k, v in shop_car.items(): l.append(k) sum_money1 = int(v["number"]) * int(v["price"]) sum_money2 += sum_money1 xyk_yue = int(dic_baihu[name]["money"]) + int(dic_baihu[name]["xyk"]) user_yue = int(dic_baihu[name]["money"]) user_xyk = int(dic_baihu[name]["xyk"]) s = " ".join([k, str(shop_car[k]["price"]), str(shop_car[k]["number"]), str(sum_money1)]) l.append(s) for i in range(len(l)): if i % 2 != 0: l1.append(l[i]) s4 = "\n".join(l1) if sum_money2 > xyk_yue and sum_money2 > user_xyk and \ sum_money2 > user_yue: print("您的余额和信用卡都不足以支付订单") shop_car.clear() return else: print(""" -------------清单--------------------- 商品名 单价 数量 总价 %s 共计:%s -------------------------------------- """ % (s4, sum_money2)) while tag: print(""" 请选择支付方式 1.余额支付 2.信用卡支付 3.余额加信用卡组合支付 4.取消支付(系统会自动清空购物车) """) choice3 = input("请选择: ") if choice3 == "1": if user_yue < sum_money2: print("您目前余额为%s,不能支付请选择其他付款方式" % user_yue) continue else: now_user_yue = user_yue - sum_money2 dic[name] = { 'pwd': dic_baihu[name]["pwd"], 'money': now_user_yue, 'xyk': dic_baihu[name]["xyk"], 'count': '0' } dic_baihu.update(dic) while tag: choice4 = input("确认输入Y/y,退出输入N/n: ") if choice4 in ["y", "Y"]: jieguo = db_xie(dic_baihu) print("正在支付中.....") time.sleep(2) if jieguo == True: print("支付成功") else: print("支付失败") elif choice3 == "2": if user_xyk < sum_money2: print("您目前信用余额为%s,不能支付请选择其他付款方式" % user_xyk) continue else: now_user_xyk = user_xyk - sum_money2 dic[name] = { 'pwd': dic_baihu[name]["pwd"], 'money': dic_baihu[name]["money"], 'xyk': now_user_xyk, 'count': '0' } dic_baihu.update(dic) while tag: choice4 = input("确认输入Y/y,退出输入N/n: ") if choice4 in ["y", "Y"]: jieguo = db_xie(dic_baihu) print("正在支付中.....") time.sleep(2) if jieguo == True: print("支付成功") else: print("支付失败") elif choice4 in ["n", "N"]: tag = False else: print("输入错误,请重新输入") continue elif choice3 == "2": if user_xyk < sum_money2: print("您目前信用余额为%s,不能支付请选择其他付款方式" % user_xyk) continue else: now_user_xyk = user_xyk - sum_money2 dic[name] = { 'pwd': dic_baihu[name]["pwd"], 'money': dic_baihu[name]["money"], 'xyk': now_user_xyk, 'count': '0' } dic_baihu.update(dic) while tag: choice4 = input("确认输入Y/y,退出输入N/n: ") if choice4 in ["y", "Y"]: jieguo = db_xie(dic_baihu) print("正在支付中.....") time.sleep(2) if jieguo == True: print("支付成功") tag = False else: print("支付失败") elif choice3 == "3": print(""" 余额为:%s 信用卡余额为:%s """ % (user_yue, user_xyk)) while tag: money_y = int(input("请输入你要使用多少余额: ")) money_x = int(input("请输入你要使用多少信用卡: ")) user_money_he = money_x + money_y now_user_money = sum_money2 - user_money_he if now_user_money < 0: print("不足以支付,请重新输入要使用的钱数") continue else: now_user_yue = int(dic_baihu[name]["money"]) - money_y now_user_xyk = int(dic_baihu[name]["xyk"]) - money_x dic[name] = { 'pwd': dic_baihu[name]["pwd"], 'money': now_user_yue, 'xyk': now_user_xyk, 'count': '0' } dic_baihu.update(dic) while tag: choice4 = input("确认输入Y/y,退出输入N/n: ") if choice4 in ["y", "Y"]: jieguo = db_xie(dic_baihu) print("正在支付中.....") time.sleep(2) if jieguo == True: print("支付成功") tag = False else: print("支付失败") elif choice3 == "4": tag = False else: print("输入错误,请重新输入") continue else: while tag: for i, v in shop_car.items(): sum_money_shop = int(shop_car[i]["price"]) * \ int(shop_car[i]["number"]) xyk_yue = int(dic_baihu[name]["money"]) + int(dic_baihu[name]["xyk"]) user_yue = int(dic_baihu[name]["money"]) user_xyk = int(dic_baihu[name]["xyk"]) l.append(i) s = " ".join([i, str(shop_car[i]["price"]), str(shop_car[i]["number"]), str(sum_money_shop)]) l.append(s) for i in range(len(l)): if i % 2 != 0: l1.append(l[i]) s4 = "\n".join(l1) if sum_money_shop > xyk_yue and sum_money_shop > user_xyk and\ sum_money_shop > user_yue: print("您的余额和信用卡都不足以支付订单") shop_car.clear() return else: print(""" -------------清单--------------------- 商品名 单价 数量 总价 %s 共计:%s -------------------------------------- """ % (s4, sum_money_shop)) while tag: print(""" 请选择支付方式 1.余额支付 2.信用卡支付 3.余额加信用卡组合支付 4.取消支付(系统会自动清空购物车) """) choice3=input("请选择: ") if choice3 == "1": if user_yue < sum_money_shop: print("您目前余额为%s,不能支付请选择其他付款方式" %user_yue) continue else: now_user_yue=user_yue - sum_money_shop dic[name]={ 'pwd': dic_baihu[name]["pwd"], 'money': now_user_yue, 'xyk': dic_baihu[name]["xyk"], 'count': '0' } dic_baihu.update(dic) while tag: choice4=input("确认输入Y/y,退出输入N/n: ") if choice4 in ["y","Y"]: jieguo=db_xie(dic_baihu) print("正在支付中.....") time.sleep(2) if jieguo == True: print("支付成功") tag=False else: print("支付失败") elif choice4 in ["n","N"]: tag=False else: print("输入错误,请重新输入") continue elif choice3 == "2": if user_xyk < sum_money_shop: print("您目前信用余额为%s,不能支付请选择其他付款方式" %user_xyk) continue else: now_user_xyk=user_xyk - sum_money_shop dic[name]={ 'pwd': dic_baihu[name]["pwd"], 'money': dic_baihu[name]["money"], 'xyk': now_user_xyk, 'count': '0' } dic_baihu.update(dic) while tag: choice4=input("确认输入Y/y,退出输入N/n: ") if choice4 in ["y","Y"]: jieguo=db_xie(dic_baihu) print("正在支付中.....") time.sleep(2) if jieguo == True: print("支付成功") tag=False else: print("支付失败") elif choice4 in ["n","N"]: tag=False else: print("输入错误,请重新输入") continue elif choice3 == "3": print(""" 余额为:%s 信用卡余额为:%s """ %(user_yue,user_xyk)) while tag: money_y=int(input("请输入你要使用多少余额: ")) money_x=int(input("请输入你要使用多少信用卡: ")) user_money_he=money_x+money_y now_user_money=sum_money_shop-user_money_he if now_user_money <0: print("不足以支付,请重新输入要使用的钱数") continue else: now_user_yue=int(dic_baihu[name]["money"])-money_y now_user_xyk=int(dic_baihu[name]["xyk"])-money_x dic[name] = { 'pwd': dic_baihu[name]["pwd"], 'money': now_user_yue, 'xyk': now_user_xyk, 'count': '0' } dic_baihu.update(dic) while tag: choice4 = input("确认输入Y/y,退出输入N/n: ") if choice4 in ["y", "Y"]: jieguo = db_xie(dic_baihu) print("正在支付中.....") time.sleep(2) if jieguo == True: print("支付成功") tag=False else: print("支付失败") elif choice3 == "4": tag = False else: print("输入错误,请重新输入") continue def db_du(): dic_baihu={} dic_heihu={} with open(db_file_baihu,"r",encoding="utf-8") as line_baihu: for i in line_baihu: q=i.strip("\n") w=q.split(":") name,pwd,money,xyk,count=w[0],w[1],w[2],w[3],w[4] dic_baihu[name]={"pwd":pwd,"money":money, "xyk":xyk,"count":count} with open(db_file_heihu, "r", encoding="utf-8") as line_heihu: for i in line_heihu: q=i.strip("\n") w=q.split(":") name,pwd,money,xyk,count=w[0],w[1],w[2],w[3],w[4] dic_heihu[name]={"pwd":pwd,"money":money, "xyk":xyk,"count":count} return dic_baihu,dic_heihu def db_xie(di_baihu,*args): l_b_k=[] l_b_v=[] l_b_h=[] l_h_k=[] l_h_v=[] l_h_h=[] with open(db_file_baihu,"w") as line: if not args: for k,v in dic_baihu.items(): l_b_k.append(k) l_b_v.append(v) for i2 in range(len(l_b_k)): a3=str(l_b_v[i2]["pwd"]) b3=str(l_b_v[i2]["money"]) c3=str(l_b_v[i2]["xyk"]) d3=str(l_b_v[i2]["count"]) l_b_h.append(l_b_k[i2]) l_b_h.append(a3) l_b_h.append(b3) l_b_h.append(c3) l_b_h.append(d3) s=":".join(l_b_h) with open(db_file_baihu,"a") as f1: f1.write("%s\n" %s) l_b_h.clear() return True else: for k1,v1 in dic_baihu.items(): l_b_k.append(k1) l_b_v.append(v1) for i3 in range(len(l_b_k)): a8=str(l_b_v[i3]["pwd"]) b8=str(l_b_v[i3]["money"]) c8=str(l_b_v[i3]["xyk"]) d8=str(l_b_v[i3]["count"]) l_b_h.append(l_b_k[i3]) l_b_h.append(a8) l_b_h.append(b8) l_b_h.append(c8) l_b_h.append(d8) s=":".join(l_b_h) with open(db_file_baihu,"a") as f2: f2.write("%s\n" %s) l_b_h.clear() l_b_h.clear() dic_heihu = args[0] for k2,v2 in dic_heihu.items(): l_h_k.append(k2) l_h_v.append(v2) with open(db_file_heihu, "w") as line: for i4 in range(len(l_h_k)): a1=str(l_h_v[i4]["pwd"]) b2=str(l_h_v[i4]["money"]) c2=str(l_h_v[i4]["xyk"]) d2=str(l_h_v[i4]["count"]) l_h_h.append(l_h_k[i4]) l_h_h.append(a1) l_h_h.append(b2) l_h_h.append(c2) l_h_h.append(d2) s1=":".join(l_h_h) with open(db_file_heihu,"a") as f3: f3.write("%s\n" %s1) l_h_h.clear() l_h_h.clear() return True if __name__ == '__main__': while tag: print(""" -----------欢迎来到建设银行ATM终端--------------- 公安温馨提示:请锁好门,做好个人安全!!! 1.登录 2.退出 ------------------------------------------------ """) choice=input("请选择: ") if choice == "1": dic_baihu,dic_heihu=db_du() if dic_baihu and dic_heihu: jieguo,*name=loging(dic_baihu,dic_heihu) if jieguo == True: while True: print(""" 建设银行欢迎您 1.查询 2.转账 3.取款 4.存款 5.信用卡业务 6.购物商城 7.返回登录 """) choice1=input("请选择您的操作:") if choice1 == "1": chaxun(name,dic_baihu) elif choice1 == "2": zhuanzhang(name,dic_baihu,dic_heihu) elif choice1 =="3": qukuan(name,dic_baihu) elif choice1 == "5": xinyongka(name,dic_baihu) elif choice1 == "6": shope(name,dic_baihu) elif choice1 == "7": break elif choice1 == "4": cunkuan(name,dic_baihu) else: print("您输入的不正确,请重新输入") continue else: print("%s暂时无法再在终端办理业务,请前往营业大厅咨询" %jieguo) else: print("很抱歉,系统正在维护升级中.........") elif choice == "2": break else: print("您输入的不正确")