完整案例在网盘
链接:https://pan.baidu.com/s/1VSfCgEjfZVVuqBFZ2AfM0w 提取码:4f8g
1 """ 2 使用者 属性:卡号,姓名 身份证 手机,密码 3 行为 4 卡: 属性 :卡号,余额,锁卡/没锁 5 行为 6 atm: 属性:使用者所有信息 7 行为:显示界面及所有行为的操作 8 管理员 属性 : 账号 密码 9 行为: 登录 10 11 main 12 """ 13 from admin import Admin 14 from atm import * 15 16 if __name__ == '__main__': 17 admin = Admin() 18 admin.login() 19 atm = Atm() 20 while True: 21 atm.print_Ui() 22 a = input("请输入编号:") 23 if a == "1": 24 atm.open() 25 if a == "2": 26 atm.cha() 27 if a == "3": 28 atm.take() 29 if a == "4": 30 atm.in1() 31 if a == "5": 32 atm.zhuang() 33 if a == "6": 34 atm.gai() 35 if a == "7": 36 atm.lockD() 37 if a == "8": 38 atm.lockJ() 39 if a == "9": 40 atm.del1() 41 if a == "t": 42 atm.tui() 43 print("退出成功") 44 break
1 """ 2 atm: 属性:使用者所有信息 3 行为:显示界面及所有行为的操作 4 """ 5 from card import Card 6 from user import User 7 import random 8 9 10 class Atm(): 11 def __init__(self): 12 self.dict = {} 13 14 def print_Ui(self): 15 16 print("************************************") 17 print("* 开户(1) 查询(2) *") 18 print("* 取款(3) 存款(4) *") 19 print("* 转账(5) 改密(6) *") 20 print("* 锁定(7) 解锁(8) *") 21 print("* 销户(9) 退出(t) *") 22 print("************************************") 23 24 def open(self): 25 name = input("请输入名字") 26 id_card = input("请输入身份证") 27 phone = input("请输入手机号") 28 user_paasword1 = input("请输入密码") 29 user_paasword2 = input("请再次输入密码") 30 if user_paasword2 != user_paasword1: 31 print("两次密码不一致,卡户失败") 32 return False 33 yu_e = int(input("请输入预存金额,不得低于10:")) 34 if yu_e < 10: 35 print("金额太少,开户失败") 36 return False 37 else: 38 card_num = random.randint(100000, 999999) 39 print("开户成功,卡号为%d" % (card_num)) 40 card = Card(card_num, yu_e, user_paasword1) 41 user = User(name, id_card, phone, card) 42 self.dict[card_num] = user 43 return False 44 def cha(self): 45 a = int(input("请输入卡号:")) 46 user = self.dict.get(a) 47 if user == None: 48 print("不存在") 49 return False 50 if user.card.lock == True: 51 print("此卡已被锁") 52 return False 53 j = 0 54 for i in range(3): 55 if input("请输入密码") != user.card.password: 56 print("密码不对") 57 j += 1 58 if j == 3: 59 user.card.lock = True 60 print("密码错误三次,此卡已被锁") 61 return False 62 else: 63 break 64 print("持卡人:%s 卡号:%s 余额:%.2f" 65 % (user.name, user.card.card, user.card.money)) 66 def take(self): 67 a = int(input("请输入卡号:")) 68 user = self.dict.get(a) 69 if user == None: 70 print("不存在") 71 return False 72 if user.card.lock == True: 73 print("此卡已被锁") 74 return False 75 j = 0 76 for i in range(3): 77 if input("请输入密码") != user.card.password: 78 print("密码不对") 79 j += 1 80 if j == 3: 81 user.card.lock = True 82 print("密码错误三次,此卡已被锁") 83 return False 84 else: 85 break 86 maney = int(input("请输入提取金额:")) 87 if user.card.money < maney: 88 print("余额不足") 89 return False 90 user.card.money -= maney 91 print("取款成功,余额为:%d" 92 % (user.card.money)) 93 def in1(self): 94 a = int(input("请输入卡号:")) 95 user = self.dict.get(a) 96 if user == None: 97 print("不存在") 98 return False 99 if user.card.lock == True: 100 print("此卡已被锁") 101 return False 102 j = 0 103 for i in range(3): 104 if input("请输入密码") != user.card.password: 105 print("密码不对") 106 j += 1 107 if j == 3: 108 user.card.lock = True 109 print("密码错误三次,此卡已被锁") 110 return False 111 else: 112 break 113 maney = int(input("请输入存入金额:")) 114 user.card.money += maney 115 print("取款成功,余额为:%d" 116 % (user.card.money)) 117 def zhuang(self): 118 a = int(input("请输入卡号:")) 119 user = self.dict.get(a) 120 if user == None: 121 print("不存在") 122 return False 123 if user.card.lock == True: 124 print("此卡已被锁") 125 return False 126 j = 0 127 for i in range(3): 128 if input("请输入密码") != user.card.password: 129 print("密码不对") 130 j += 1 131 if j == 3: 132 user.card.lock = True 133 print("密码错误三次,此卡已被锁") 134 return False 135 else: 136 break 137 maney = int(input("请输入转账金额:")) 138 if user.card.money < maney: 139 print("余额不足") 140 return False 141 user.card.money -= maney 142 a = int(input("请输入卡号:")) 143 x = self.dict.get(a) 144 if x == None: 145 print("不存在") 146 return False 147 if x.card.lock == True: 148 print("此卡已被锁") 149 return False 150 x.card.money += maney 151 print("转账成功") 152 def gai(self): 153 a = int(input("请输入卡号:")) 154 user = self.dict.get(a) 155 if user == None: 156 print("不存在") 157 return False 158 if user.card.lock == True: 159 print("此卡已被锁") 160 return False 161 j = 0 162 for i in range(3): 163 if input("请输入密码") != user.card.password: 164 print("密码不对") 165 j += 1 166 if j == 3: 167 user.card.lock = True 168 print("密码错误三次,此卡已被锁") 169 return False 170 else: 171 break 172 a = input("请输入新密码") 173 user.card.password = a 174 print("修改成功") 175 def lockD(self): 176 a = int(input("请输入卡号:")) 177 user = self.dict.get(a) 178 if user == None: 179 print("不存在") 180 return False 181 if user.card.lock == True: 182 print("此卡已被锁") 183 return False 184 j = 0 185 for i in range(3): 186 if input("请输入密码") != user.card.password: 187 print("密码不对") 188 j += 1 189 if j == 3: 190 user.card.lock = True 191 print("密码错误三次,此卡已被锁") 192 return False 193 else: 194 break 195 user.card.lock = True 196 print("锁卡成功") 197 def lockJ(self): 198 a = int(input("请输入卡号:")) 199 user = self.dict.get(a) 200 if user == None: 201 print("不存在") 202 return False 203 j = 0 204 for i in range(3): 205 if input("请输入密码") != user.card.password: 206 print("密码不对") 207 j += 1 208 if j == 3: 209 user.card.lock = True 210 print("密码错误三次,此卡已被锁") 211 return False 212 else: 213 break 214 user.card.lock = False 215 print("解锁成功") 216 def del1(self): 217 a = int(input("请输入卡号:")) 218 user = self.dict.get(a) 219 if user == None: 220 print("不存在") 221 return False 222 if user.card.lock == True: 223 print("此卡已被锁") 224 return False 225 j = 0 226 for i in range(3): 227 if input("请输入密码") != user.card.password: 228 print("密码不对") 229 j += 1 230 if j == 3: 231 user.card.lock = True 232 print("密码错误三次,此卡已被锁") 233 return False 234 else: 235 break 236 self.dict.pop(a) 237 print("销户成功") 238 def tui(self): 239 pass