1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
| import random
display=''' ********************** * * * welcome to bank * * * ********************** ''' display2=''' ********************** * 1.登陆 2.开户 * * 3.查询 4.取款 * * 5.存款 6.退出 * * 7.转账 8.改密 * * 9.锁卡 0.解锁 * ********************** ''' def getkamun(userdict): userlist = list(userdict) kanum = userdict.keys() while 1: kalist =[] while len(kalist)<3: i = random.randrange(10) if str(i) not in kalist: kalist.append(str(i)) kanum="".join(kalist) if kanum in userlist: continue else: break return kanum
def register(userdict): idcard =input("身份证号:") name = input("用户名:") phone =input("电话号码:") money=int(input("预存款:")) while 1: psd1 =input("密码:") psd2 =input("确认密码:") if psd1==psd2: psd=psd2 break else: print("密码不一致,重新输入") kanum=getkamun(userdict) user ={'idcard':idcard,'name':name,'phone':phone,'money':money,'psd':psd,'kanum':kanum,'suo':False} return user
def login(userdict): usernum = input("请输入卡号:") user =userdict.get(usernum) if user==None: print("卡号不存在") return else: if user['suo']: print("已锁定,请解锁后登陆") return for i in range(4): psd = input("请输入密码:") if usernum ==user.get('kanum') and psd ==user.get('psd'): print("登陆成功") return user.get('kanum') else: print("登陆失败,还有%d次机会"%i) continue else: user['suo']=True print("登陆次数超过三次,已锁定")
def refer(kanum): user = userdict.get(kanum) money = user['money'] print("当前余额为%d"%money) return None
def fund(kanum): user = userdict.get(kanum) money=user['money'] money += eval(input("输入金额")) user['money']=money print("成功!当前余额为%d" % money) return None
def draw(kanum): user = userdict.get(kanum) money=user['money'] while 1: money -= eval(input("输入金额")) if money>=0: user['money']=money print("成功!当前余额为%d"%money) break else: print("输入大于余额,重新输入") break return None
def tran(kanum,userdict): user = userdict[kanum] print(user) obj = input("请输入卡号:") if obj not in userdict: print("卡号不存在") else: money2 = int(input("请输入转账金额:")) if money2<user['money']: user['money'] -= money2 userdict.get(obj)['money'] +=money2 print("转账成功,余额为%d"%user['money']) return else: print("余额不足")
def changepsd(kanum,userdict): user = userdict[kanum] oldpsd = input("请输入当前密码:") if oldpsd == user['psd']: newpsd = input("请输入新密码:") user['psd'] = newpsd print("修改成功") else: print("密码错误")
def lock(kanum,userdict): kanum = input("请输入您的卡号:") if kanum in userdict: idcard = input("请输入身份证号码:") name = input("请输入姓名:") phone = input("请输入电话:") user = userdict[kanum] if idcard==user['idcard'] and name==user['name'] and phone==user['phone']: user['suo']=True print("锁定成功") return else: print("信息有误") else: print("卡号不存在") return
def unlock(userdict): kanum = input("请输入卡号:") if kanum in userdict: idcard = input("请输入身份证:") name = input("请输入姓名:") phone = input("请输入电话:") user = userdict[kanum] if idcard==user['idcard'] and name==user['name'] and phone==user['phone']: user['suo']=False print("解锁成功") return else: print("信息有误") else: print("卡号不存在") return
def welcome(): print(display)
welcome() userdict={} login_state = None money =0 n = 0 while 1: print(display2) n =input("用户选择要操作:") if n=='1': login_state = login(userdict) print(userdict) elif n=='2': user=register(userdict) kanum=user.get('kanum') userdict[kanum]=user print('卡号为:%s'%kanum) elif n=='3': print(userdict) if login_state: refer(login_state) else: print("请先登陆") elif n=='4': if login_state: draw(login_state) else: print("请先登陆") elif n=='5': if login_state: fund(login_state) else: print("请先登陆") elif n=='6': login_state = None print('退出登陆') elif n=='7': if login_state: tran(login_state, userdict) else: print("请先登陆") elif n=='8': if login_state: changepsd(login_state, userdict) else: print("请先登陆") elif n=='9': n=lock(login_state, userdict) elif n=='0': unlock(userdict) else: print("输入有误,退出系统") break
|