1. 程式人生 > >day 17 作業(2) 銀行案例效果

day 17 作業(2) 銀行案例效果

完整案例在網盤 

連結: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