亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

python實(shí)現(xiàn)銀行管理系統(tǒng)

 更新時(shí)間:2019年10月25日 08:50:47   作者:放開這小書包  
這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)銀行管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

python實(shí)現(xiàn)銀行管理系統(tǒng),供大家參考,具體內(nèi)容如下

有的地方用的方法的比較復(fù)雜,主要是為回顧更多的知識(shí)

test1用來存類和函數(shù)

#test1.py 
import random #用來隨機(jī)產(chǎn)生卡號(hào)
import pickle #序列化,用來存放和取出產(chǎn)生的用戶數(shù)據(jù)
import os #產(chǎn)生文件
import re #正則表達(dá)式,用來判斷身份證和手機(jī)號(hào),其他地方也可以使用
class Card:
 def __init__(self,cardId,password,money=0):
 self.cardId=cardId
 self.password=password
 self.money=money
class User(Card):
 def __init__(self,username,phone,uid,card):
 self.username=username
 self.phone=phone
 self.uid=uid
 self.user_card=card #User繼承Card對(duì)象
class Bank(User): #Bank 繼承User,Bank是序列化的對(duì)象,所以將其變?yōu)樽值?
 def __init__(self,user):
 self.cardId=user.user_card.cardId 
 self.user=user 
 self.users={self.cardId:self.user} #鍵,卡號(hào) :值,User對(duì)象 

def generate_cardid(): #方法一 產(chǎn)生卡號(hào)
 list=[]
 for i in range(0,11):
 n=random.randint(0,9)
 n=str(n)
 list.append(n)
 # str="".join(list)
 return list
# generate_cardid()
# user_cardId=input("請(qǐng)輸入您的賬號(hào):")
def create_user(): #方法2:開戶
 while True:
 uid=input("請(qǐng)輸入身份證:")
 realut=re.fullmatch("\d{17}[\d,X]",uid) #正則判斷身份證是否合理
 if realut:
 uid=realut.group()
 break
 else:
 print("格式不合法")
 continue
 username=input("請(qǐng)輸入姓名:")
 while True:
 phone=input("請(qǐng)輸入手機(jī)號(hào)碼:")
 realut = re.fullmatch("1\d{10}", phone) #正則判斷手機(jī)號(hào)是否合理,其他需要判斷的地方都可以判斷,我就不再使用了
 if realut:
 phone=realut.group()
 # print(phone)
 break
 else:
 print("格式不合法")
 continue
 list=generate_cardid() #得到卡號(hào)列表
 cardId="".join(list) #將卡號(hào)變成字符串,字符串的卡號(hào)才能做成鍵
 print(f"您的卡號(hào)為:{cardId}")
 while True:
 password1=input("請(qǐng)輸入密碼:")
 password2=input("再次輸入密碼確認(rèn):")
 if password1==password2:
 password=password1
 break
 else :
 print("兩次密碼不同,請(qǐng)重新輸入!")
 continue
 card=Card(cardId,password) 
 user=User(uid,username,phone,card)
 bank=Bank(user) #產(chǎn)生bank對(duì)象
 with open(f"data\\{cardId}.txt","ab") as file_w: #重點(diǎn):創(chuàng)建一個(gè)文件夾data來存放產(chǎn)生的bank對(duì)象,每個(gè)對(duì)象根據(jù)卡號(hào)產(chǎn)生一個(gè)txt文件,用來存放用戶的所有數(shù)據(jù)
 pickle.dump(bank,file_w) #將bank 序列化保存到文檔中
# create_user()

def user_login(user_cardId): #登錄

 if os.path.exists(f"data\\{user_cardId}.txt"):
 with open(f"data\\{user_cardId}.txt", "rb") as file_r:
 u_data = pickle.load(file_r) #根據(jù)卡號(hào)取出txt文檔,反序列化取出數(shù)據(jù)
 if u_data.cardId == user_cardId: #u_data是一個(gè)字典,鍵是卡號(hào),值是user對(duì)象 
 n = 1
 while True:
 if n <= 3:
 user_pw = input("請(qǐng)輸入密碼:")
 if u_data.user.user_card.password == user_pw:
 return True
 else:
 print("密碼錯(cuò)誤!")
 n+=1
 continue
 else:
 print("三次輸入密碼錯(cuò)誤!")
 return
 else:
 print("沒有該用戶")

# user_login(user_cardId)
def save_money(user_cardId): # 方法4:存錢
 if user_login(user_cardId): #如果登錄成功
 money=int(input("請(qǐng)您輸入存錢金額:"))
 with open(f"data\\{user_cardId}.txt", "rb") as file_r:
 u_data = pickle.load(file_r)
 u_data.user.user_card.money=u_data.user.user_card.money+money
 print("您的余額為:",u_data.user.user_card.money)
 with open(f"data\\{user_cardId}.txt", "wb") as file_w: #這里要用wb,而不是ab,改變數(shù)據(jù)后,需要覆蓋原來的數(shù)據(jù),而不是添加
 pickle.dump(u_data, file_w)
# save_money()

def withdraw_money(user_cardId): # 方法5:取錢
 if user_login(user_cardId):
 money=int(input("請(qǐng)您輸入取款金額:"))
 with open(f"data\\{user_cardId}.txt", "rb") as file_r:
 u_data = pickle.load(file_r)
 if money>u_data.user.user_card.money:
 print("余額不足")
 else:
 u_data.user.user_card.money=u_data.user.user_card.money-money
 print("您的余額為:", u_data.user.user_card.money)
 with open(f"data\\{user_cardId}.txt", "wb") as file_w:
 pickle.dump(u_data, file_w)

# withdraw_money()

def transfer_accounts(user_cardId): #方法6,轉(zhuǎn)賬
 if user_login(user_cardId):
 with open(f"data\\{user_cardId}.txt", "rb") as file_r:
 u_data = pickle.load(file_r)
 while True:
 money = int(input("請(qǐng)您轉(zhuǎn)賬取款金額:"))
 if money > u_data.user.user_card.money:
 print("余額不足")
 break
 else:
 cardId=int(input("請(qǐng)您對(duì)方卡號(hào):"))
 if os.path.exists(f"data\\{cardId}.txt"): #如果對(duì)方卡號(hào)存在
 u_data.user.user_card.money = u_data.user.user_card.money - money #自己的money減
 print("您的余額為:", u_data.user.user_card.money)
 with open(f"data\\{user_cardId}.txt", "wb") as file_w:
 pickle.dump(u_data, file_w)

 with open(f"data\\{cardId}.txt", "rb") as file_r1: #根據(jù)對(duì)方的卡號(hào)進(jìn)行查找對(duì)方的數(shù)據(jù)
 u_data1 = pickle.load(file_r1)
 with open(f"data\\{cardId}.txt", "wb") as file_w1:
 u_data1.user.user_card.money = u_data1.user.user_card.money + money #對(duì)方money加
 pickle.dump(u_data1, file_w1)
 print("轉(zhuǎn)賬成功")
 break
 else:
 print("該用戶不存在")
 break

# transfer_accounts()

def select_user(user_cardId): # 方法7:查詢余額
 if user_login(user_cardId):
 with open(f"data\\{user_cardId}.txt", "rb") as file_r:
 u_data = pickle.load(file_r)
 print("您的余額為:",u_data.user.user_card.money)
# select_user()

def update_password(user_cardId): # 方法8:修改密碼
 if user_login(user_cardId):
 while True:
 pw1=input("請(qǐng)輸入新密碼:")
 pw2=input("請(qǐng)?jiān)俅屋斎朊艽a:")
 if pw1==pw2:
 with open(f"data\\{user_cardId}.txt", "rb") as file_r:
 u_data = pickle.load(file_r)
 u_data.user.user_card.password=pw1
 with open(f"data\\{user_cardId}.txt", "wb") as file_w:
 pickle.dump(u_data, file_w)
 break

 else:
 print("兩次密碼不相同")
 continue

test2用來調(diào)用test1中的函數(shù)

import test1
import os
T =True
while True:
 user_cardId=input("請(qǐng)輸入您的賬號(hào),退出請(qǐng)按0,注冊(cè)請(qǐng)按1:\n")
 if os.path.exists(f"data\\{user_cardId}.txt"):
 true=True
 while true:
 x = input("[2]查詢余額 [3]取款 [4]存錢 [5]轉(zhuǎn)賬 [6]修改密碼 [7]退出系統(tǒng)\n"
 "請(qǐng)選擇需要的操作輸入對(duì)應(yīng)的數(shù)字:"
 if x=="2": #鍵盤輸入默認(rèn)是str類型
 test1.select_user(user_cardId)
 continue
 elif x=="3":
 test1.withdraw_money(user_cardId)
 continue

 elif x=="4":
 test1.save_money(user_cardId)
 continue
 elif x=="5":
 test1.transfer_accounts(user_cardId)
 continue
 elif x=="6":
 test1.update_password(user_cardId)
 continue
 elif x=="7":
 true=False
 else:
 print("沒有對(duì)應(yīng)操作")
 continue
 elif user_cardId=="0":
 print("歡迎再次使用")
 break
 elif user_cardId=="1":
 test1.create_user()
 continue

 else :
 print("沒有該賬戶")
 T=True
 while T:
 num = input("需要注冊(cè)賬號(hào)請(qǐng)按1,退出注冊(cè)服務(wù)請(qǐng)按0:")
 if num =="1":
 test1.create_user()
 elif num =="0":
 print("歡迎再次使用")
 T =False
 break
 else:
 print("沒有對(duì)應(yīng)操作")
 continue
 break

更多學(xué)習(xí)資料請(qǐng)關(guān)注專題《管理系統(tǒng)開發(fā)》。

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • python 在屏幕上逐字顯示一行字的實(shí)例

    python 在屏幕上逐字顯示一行字的實(shí)例

    今天小編就為大家分享一篇python 在屏幕上逐字顯示一行字的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2018-12-12
  • 關(guān)于PyQt5中QtGui.QImage圖片顯示問題解析

    關(guān)于PyQt5中QtGui.QImage圖片顯示問題解析

    PyQt作為Qt語言的Python擴(kuò)展,可以用來方便快速的開發(fā)界面應(yīng)用,本文重點(diǎn)給大家介紹PyQt5中的QtGui.QImage圖片顯示問題分析,需要的朋友可以參考下
    2022-03-03
  • 詳解python--模擬輪盤抽獎(jiǎng)游戲

    詳解python--模擬輪盤抽獎(jiǎng)游戲

    這篇文章主要介紹了python模擬輪盤抽獎(jiǎng)游戲,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-04-04
  • 已解決卸載pip重新安裝的方法

    已解決卸載pip重新安裝的方法

    粉絲群里面的一個(gè)小伙伴遇到問題跑來私信我,想用卸載pip重新安裝pip,但是發(fā)生了報(bào)錯(cuò)(當(dāng)時(shí)他心里瞬間涼了一大截,跑來找我求助,然后順利幫助他解決了,順便記錄一下希望可以幫助到更多遇到這個(gè)問題的小伙伴
    2023-04-04
  • python自定義分頁器的實(shí)現(xiàn)

    python自定義分頁器的實(shí)現(xiàn)

    這篇文章主要介紹了python自定義分頁器的實(shí)現(xiàn),通過自定義分頁器封裝展開主題并對(duì)其實(shí)用方法簡單介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下
    2022-04-04
  • Python中is與==的使用區(qū)別詳解

    Python中is與==的使用區(qū)別詳解

    這篇文章小編主要給大家講解的是Python中is與==的使用區(qū)別的相關(guān)資料,需要的下伙伴可以參考下面文章內(nèi)容的具體詳細(xì)資料
    2021-09-09
  • python?中的jieba分詞庫

    python?中的jieba分詞庫

    這篇文章主要介紹了python中的jieba分詞庫,jieba?庫是優(yōu)秀的中文分詞第三方庫,中文文本需要通過分詞獲得單個(gè)的詞語,下面文章的的詳細(xì)內(nèi)容,需要的朋友可以參考一下
    2021-11-11
  • 王純業(yè)的Python學(xué)習(xí)筆記 下載

    王純業(yè)的Python學(xué)習(xí)筆記 下載

    這篇文章主要介紹了王純業(yè)的Python學(xué)習(xí)筆記 下載
    2007-02-02
  • python被修飾的函數(shù)消失問題解決(基于wraps函數(shù))

    python被修飾的函數(shù)消失問題解決(基于wraps函數(shù))

    這篇文章主要介紹了python被修飾的函數(shù)消失問題解決(基于wraps函數(shù)),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-11-11
  • 使用Python批量移除Word文檔水印的代碼示例

    使用Python批量移除Word文檔水印的代碼示例

    移除Word文檔中的水印可以減少不必要的麻煩,通過使用Python這樣的編程語言,我們可以輕松實(shí)現(xiàn)自動(dòng)化操作,高效地移除Word文檔中的水印,確保文檔的專業(yè)性和準(zhǔn)確性,本文將介紹如何使用Python批量移除Word文檔中的水印
    2024-07-07

最新評(píng)論