1. 程式人生 > >python 銀行系統

python 銀行系統

#銀行類
#屬性  使用者
#方法
#1、開戶 2、查詢 3、存款 4、取款 5、轉賬 6、銷戶 7、補卡 8、解凍 9、凍結 0、退出  + 登入介面 +管理員登入
#使用者
#屬性
#1、姓名 2、 身份證號 3、 電話號 4、卡號 5、密碼 6、錯誤次數
import time
import random
class Preson(object):                     #人類
    def __init__(self):
        self.name = ''
        self.idNum = ''
        self.phoneNum = ''
        self.cardNum = ""
self.cardPass_word = '' self.cardCode = 0 self.money = 0 class Bank(object): #銀行類 dict1 = {} list1 = [] def shuijikahao(self): #生成六位隨機卡號 str = "1234567890" str1 = "" while True: for x in range(6): str1 += random.choice(str) if
str1 not in Bank.list1: Bank.list1.append(str1) break return str1 def open(self): #開戶方法 per1 = Preson() per1.name = input("請輸入姓名:") per1.idNum = input("請輸入身份證號:") while True: per1.cardPass_word = input("請輸入登入密碼:"
) a = input("請確認登入密碼:") if a == per1.cardPass_word: break else: print("兩側密碼不一致,請重新輸入") per1.phoneNum = input("請輸入聯絡電話:") while True: per1.money = int(input("請輸入預存款金額:")) if per1.money <= 0: print("預存款金額必須大於0") else: break c = Bank.shuijikahao(self) per1.cardNum = c Bank.dict1[c] = per1 print("開戶成功,您的卡號為%s,請牢記您的卡號"%per1.cardNum) def see(self): #查詢方法 a = input("請輸入您的卡號") if a not in Bank.dict1.keys(): #判斷是否存在卡號 print("卡號不存在,返回上一級") time.sleep(1) return -1 if Bank.dict1[a].cardCode >= 3: #判斷錯誤次數是否已有三次 print("已錯誤3次,卡已被凍結,請解凍後再試") print("返回上一級...........") time.sleep(1) return -1 else: while Bank.dict1[a].cardCode < 3: b = input("請輸入密碼") if b == Bank.dict1[a].cardPass_word: #判斷密碼是否正確 Bank.dict1[a].cardCode = 0 print("密碼正確,您當前餘額為:",Bank.dict1[a].money) print("返回上一級...........") time.sleep(1) return -1 else: print("密碼錯誤,請重新輸入") Bank.dict1[a].cardCode += 1 print("已輸入錯誤3次,卡已被凍結,請解凍後再試") print("返回上一級...........") time.sleep(1) def saves(self): #存款方法 a = input("請輸入您的卡號") if a not in Bank.dict1.keys(): print("卡號不存在,返回上一級") time.sleep(1) return -1 if Bank.dict1[a].cardCode >= 3: print("已錯誤3次,卡已被凍結,請解凍後再試......") print("返回上一級.......") time.sleep(1) return -1 else: while Bank.dict1[a].cardCode < 3: b = input("請輸入密碼") if b == Bank.dict1[a].cardPass_word: Bank.dict1[a].cardCode = 0 while True: #判斷存款金額 c= int(input("密碼正確,請輸入您的存款金額:")) if c <= 0: print("存款金額必須大於0") else: break Bank.dict1[a].money += c print("存款成功您當前餘額為:", Bank.dict1[a].money) print("正在返回上一級.....") time.sleep(1) return -1 else: print("密碼錯誤,請重新輸入") Bank.dict1[a].cardCode += 1 print("已輸入錯誤3次,卡已被凍結,請解凍後再試") print("返回上一級.......") time.sleep(1) def draw(self): a = input("請輸入您的卡號") if a not in Bank.dict1.keys(): print("卡號不存在,返回上一級") time.sleep(1) return -1 if Bank.dict1[a].cardCode >= 3: print("已錯誤3次,卡已被凍結,請解凍後再試......") print("返回上一級.......") time.sleep(1) return -1 else: while Bank.dict1[a].cardCode < 3: b = input("請輸入密碼") if b == Bank.dict1[a].cardPass_word: Bank.dict1[a].cardCode = 0 while True: c = int(input("密碼正確,請輸入您的取款金額:")) if c > Bank.dict1[a].money: print("餘額不足,請重新輸入取款金額") elif c <= 0: print("取款金額必須大於0") else: break Bank.dict1[a].money -= c print("取款成功您當前餘額為:", Bank.dict1[a].money) print("正在返回上一級.....") time.sleep(1) return -1 else: print("密碼錯誤,請重新輸入") Bank.dict1[a].cardCode += 1 print("已輸入錯誤3次,卡已被凍結,請解凍後再試") print("返回上一級.......") time.sleep(1) def transfer(self):#轉賬 a = input("請輸入您的卡號") if a not in Bank.dict1.keys(): print("卡號不存在,返回上一級") time.sleep(1) return -1 if Bank.dict1[a].cardCode >= 3: print("已錯誤3次,卡已被凍結,請解凍後再試......") print("返回上一級.......") time.sleep(1) return -1 else: while Bank.dict1[a].cardCode < 3: b = input("請輸入密碼") if b == Bank.dict1[a].cardPass_word: Bank.dict1[a].cardCode = 0 c = input("密碼正確,請輸入你想轉賬的卡號:") if c not in Bank.dict1.keys(): print("卡號不存在,返回上一級") time.sleep(1) return -1 if Bank.dict1[c].cardCode >= 3: print("您想轉賬的卡已被凍結,請解凍後再試......") print("返回上一級.......") time.sleep(1) return -1 if a == c: print("不能給自己的卡轉賬,返回上一級") time.sleep(1) return -1 else: while True: d = int(input("請輸入您想轉賬的金額:")) if d > Bank.dict1[a].money: print("餘額不足,請重新輸入轉賬金額") elif d <= 0: print("轉賬金額必須大於0") else: break Bank.dict1[a].money -= d Bank.dict1[c].money += d print("轉賬成功,您當前餘額為:", Bank.dict1[a].money ) print("正在返回上一級.....") time.sleep(1) return -1 else: print("密碼錯誤,請重新輸入") Bank.dict1[a].cardCode += 1 print("已輸入錯誤3次,卡已被凍結,請解凍後再試") print("返回上一級.......") time.sleep(1) def close(self): a = input("請輸入您的卡號") if a not in Bank.dict1.keys(): print("卡號不存在,返回上一級") time.sleep(1) return -1 if Bank.dict1[a].cardCode >= 3: print("已錯誤3次,卡已被凍結,請解凍後再試") print("返回上一級...........") time.sleep(1) return -1 else: while Bank.dict1[a].cardCode < 3: b = input("請輸入密碼") if b == Bank.dict1[a].cardPass_word: Bank.dict1[a].cardCode = 0 c = input("請輸入您的姓名:") d = input("請輸入您的身份證號:") e = input("請輸入您開卡時預留手機號:") if c != Bank.dict1[a].name or d != Bank.dict1[a].idNum or e != Bank.dict1[a].phoneNum: print("資訊驗證錯誤,返回上一級") return -1 print("資訊驗證成功") if input("確定銷戶嗎?YES.NO").lower() == 'YES'.lower(): del Bank.dict1[a] print("銷戶成功......") else: print("沒有銷戶......") print("返回上一級...........") time.sleep(1) return -1 else: print("密碼錯誤,請重新輸入") Bank.dict1[a].cardCode += 1 print("已輸入錯誤3次,卡已被凍結,請解凍後再試") print("返回上一級...........") time.sleep(1) def re_make(self): a = input("請輸入您的卡號") if a not in Bank.dict1.keys(): print("卡號不存在,返回上一級") time.sleep(1) return -1 if Bank.dict1[a].cardCode >= 3: print("已錯誤3次,卡已被凍結,請解凍後再試") print("返回上一級...........") time.sleep(1) return -1 else: while Bank.dict1[a].cardCode < 3: b = input("請輸入密碼") if b == Bank.dict1[a].cardPass_word: Bank.dict1[a].cardCode = 0 while Bank.dict1[a].cardCode < 3: c = input("請輸入您的姓名:") d = input("請輸入您的身份證號:") e = input("請輸入您開卡時預留手機號:") if c == Bank.dict1[a].name and d == Bank.dict1[a].idNum and e == Bank.dict1[a].phoneNum: f = Bank.shuijikahao(self) print("補卡成功,請取走您的卡片,您當前卡號為:",f) time.sleep(1) Bank.dict1[f] = Bank.dict1[a] del Bank.dict1[a] return -1 else: print("驗證失敗,您的輸入有錯誤.....") Bank.dict1[a].cardCode += 1 print("返回上一級...........") time.sleep(1) return -1 else: print("密碼錯誤,請重新輸入") Bank.dict1[a].cardCode += 1 print("已輸入錯誤3次,卡已被凍結,請解凍後再試") print("返回上一級...........") time.sleep(1) def unfreeze(self): a = input("請輸入您的卡號") if a not in Bank.dict1.keys(): print("卡號不存在,返回上一級") time.sleep(1) return -1 else: b = 0 while b < 3: c = input("請輸入您的姓名:") d = input("請輸入您的身份證號:") e = input("請輸入您開卡時預留手機號:") if c == Bank.dict1[a].name and d == Bank.dict1[a].idNum and e == Bank.dict1[a].phoneNum: print("解凍成功.......") time.sleep(1) Bank.dict1[a].cardCode = 0 return -1 else: print("驗證失敗,您的輸入有錯誤.....") b += 1 print("已輸入錯誤3次,解凍失敗,卡已登出") del Bank.dict1[a] print("返回上一級...........") time.sleep(1) def freeze(self): a = input("請輸入您的卡號") if a not in Bank.dict1.keys(): print("卡號不存在,返回上一級") time.sleep(1) return -1 if Bank.dict1[a].cardCode >= 3: print("已錯誤3次,卡已被凍結,請解凍後再試") print("返回上一級...........") time.sleep(1) return -1 else: while Bank.dict1[a].cardCode < 3: b = input("請輸入密碼") if b == Bank.dict1[a].cardPass_word: Bank.dict1[a].cardCode = 3 print("凍結成功.......") print("返回上一級...........") time.sleep(1) return -1 else: print("密碼錯誤,請重新輸入") Bank.dict1[a].cardCode += 1 print("已輸入錯誤3次,卡已被凍結,請解凍後再試") print("返回上一級...........") time.sleep(1) def changepw(self): a = input("請輸入您的卡號") if a not in Bank.dict1.keys(): print("卡號不存在,返回上一級") time.sleep(1) return -1 if Bank.dict1[a].cardCode >= 3: print("已錯誤3次,卡已被凍結,請解凍後再試") print("返回上一級...........") time.sleep(1) return -1 else: while Bank.dict1[a].cardCode < 3: b = input("請輸入密碼") if b == Bank.dict1[a].cardPass_word: c = input("請輸入新的密碼....") while c != input("請確認您的新密碼"): c = input("請輸入新的密碼....") Bank.dict1[a].cardPass_word = c print("密碼重置成功") print("返回上一級...........") time.sleep(1) return -1 else: print("密碼錯誤,請重新輸入") Bank.dict1[a].cardCode += 1 print("已輸入錯誤3次,卡已被凍結,請解凍後再試") print("返回上一級...........") time.sleep(1) def exit1(self): while 1: c = input("請輸入管理員賬號:") d = input("請輸入管理員密碼:") if c == "admin" and d == "123456": print("登入成功,正在退出系統.....") time.sleep(1) break else: print("賬號或密碼錯誤,請重新輸入") time.sleep(1) exit() def admin_register(self): print("******************************************************************") print("* *") print("* *") print("* 銀行系統 *") print("* *") print("* *") print("******************************************************************") while 1: a = input("請輸入管理員賬號:") b = input("請輸入管理員密碼:") if a == "admin" and b == "123456": print("登入成功,正在跳轉......") time.sleep(1) break else: print("賬號或密碼錯誤,請重新輸入") time.sleep(1) while 1: print("******************************************************************") print("* 1、開戶 2、查詢 *") print("* 3、存款 4、取款 *") print("* 5、轉賬 6、銷戶 *") print("* 7、補卡 8、解凍 *") print("* 9、凍結 0、更改密碼 *") print("* t、退出 *") print("******************************************************************") a = input("請輸入操作:") if a == "1": self.open() elif a == "2": self.see() elif a == "3": self.saves() elif a == "4": self.draw() elif a == "5": self.transfer() elif a == "6": self.close() elif a == "7": self.re_make() elif a == "8": self.unfreeze() elif a == "9": self.freeze() elif a == "0": self.changepw() elif a == "t": self.exit1() else: print("輸入錯誤,請重新輸入......") a = Bank() a.admin_register()