最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

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

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

test1用來(lái)存類(lèi)和函數(shù)

#test1.py 
import random #用來(lái)隨機(jī)產(chǎn)生卡號(hào)
import pickle #序列化,用來(lái)存放和取出產(chǎn)生的用戶(hù)數(shù)據(jù)
import os #產(chǎn)生文件
import re #正則表達(dá)式,用來(lái)判斷身份證和手機(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:開(kāi)戶(hù)
 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來(lái)存放產(chǎn)生的bank對(duì)象,每個(gè)對(duì)象根據(jù)卡號(hào)產(chǎn)生一個(gè)txt文件,用來(lái)存放用戶(hù)的所有數(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("沒(méi)有該用戶(hù)")

# user_login(user_cardId)
def save_money(user_cardId): # 方法4:存錢(qián)
 if user_login(user_cardId): #如果登錄成功
 money=int(input("請(qǐng)您輸入存錢(qián)金額:"))
 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ù)后,需要覆蓋原來(lái)的數(shù)據(jù),而不是添加
 pickle.dump(u_data, file_w)
# save_money()

def withdraw_money(user_cardId): # 方法5:取錢(qián)
 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("該用戶(hù)不存在")
 break

# transfer_accounts()

def select_user(user_cardId): # 方法7:查詢(xún)余額
 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用來(lái)調(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]查詢(xún)余額 [3]取款 [4]存錢(qián) [5]轉(zhuǎn)賬 [6]修改密碼 [7]退出系統(tǒng)\n"
 "請(qǐng)選擇需要的操作輸入對(duì)應(yīng)的數(shù)字:"
 if x=="2": #鍵盤(pán)輸入默認(rèn)是str類(lèi)型
 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("沒(méi)有對(duì)應(yīng)操作")
 continue
 elif user_cardId=="0":
 print("歡迎再次使用")
 break
 elif user_cardId=="1":
 test1.create_user()
 continue

 else :
 print("沒(méi)有該賬戶(hù)")
 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("沒(méi)有對(duì)應(yīng)操作")
 continue
 break

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

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

相關(guān)文章

  • python實(shí)現(xiàn)梯度下降算法的實(shí)例詳解

    python實(shí)現(xiàn)梯度下降算法的實(shí)例詳解

    在本篇文章里小編給大家整理的是一篇關(guān)于python實(shí)現(xiàn)梯度下降算法的實(shí)例詳解內(nèi)容,需要的朋友們可以參考下。
    2020-08-08
  • python3基礎(chǔ)之集合set詳解

    python3基礎(chǔ)之集合set詳解

    大家好,本篇文章主要講的是python3基礎(chǔ)之集合set詳解,感興趣的同學(xué)趕快來(lái)看一看吧,對(duì)你有幫助的話(huà)記得收藏一下,方便下次瀏覽
    2021-12-12
  • 利用Python繪制端午節(jié)祝福動(dòng)畫(huà)

    利用Python繪制端午節(jié)祝福動(dòng)畫(huà)

    這篇文章主要介紹了如何利用Python繪制一個(gè)端午節(jié)的祝福動(dòng)畫(huà),文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)Python有一定的幫助,需要的可以參考一下
    2023-06-06
  • python 爬取小說(shuō)并下載的示例

    python 爬取小說(shuō)并下載的示例

    這篇文章主要介紹了python 爬取小說(shuō)并下載的示例,幫助大家更好的理解和學(xué)習(xí)python爬蟲(chóng),感興趣的朋友可以了解下
    2020-12-12
  • 從零教你安裝pytorch并在pycharm中使用

    從零教你安裝pytorch并在pycharm中使用

    本文詳細(xì)介紹了如何使用Anaconda包管理工具創(chuàng)建虛擬環(huán)境,并安裝CUDA加速平臺(tái)和PyTorch庫(kù),同時(shí)在PyCharm中配置和使用PyTorch進(jìn)行深度學(xué)習(xí)任務(wù),需要的朋友可以參考下
    2025-02-02
  • python如何生成textgrid文件

    python如何生成textgrid文件

    這篇文章主要介紹了python如何生成textgrid文件,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧
    2024-07-07
  • python復(fù)合條件下的字典排序

    python復(fù)合條件下的字典排序

    這篇文章主要介紹了python復(fù)合條件下的字典排序,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-12-12
  • Python實(shí)現(xiàn)從訂閱源下載圖片的方法

    Python實(shí)現(xiàn)從訂閱源下載圖片的方法

    這篇文章主要介紹了Python實(shí)現(xiàn)從訂閱源下載圖片的方法,涉及Python采集的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-03-03
  • Python flashtext文本搜索和替換操作庫(kù)功能使用探索

    Python flashtext文本搜索和替換操作庫(kù)功能使用探索

    本文將深入介紹Python flashtext庫(kù),包括其基本用法、功能特性、示例代碼以及實(shí)際應(yīng)用場(chǎng)景,以幫助大家更好地利用這個(gè)有用的工具
    2024-01-01
  • Python使用cProfile進(jìn)行性能分析

    Python使用cProfile進(jìn)行性能分析

    cProfile是Python標(biāo)準(zhǔn)庫(kù)中的一個(gè)模塊,用于收集代碼的性能數(shù)據(jù),這篇文章主要為大家詳細(xì)介紹了如何使用cProfile進(jìn)行性能分析,需要的可以參考下
    2024-12-12

最新評(píng)論

德安县| 富平县| 泗水县| 绵阳市| 扬州市| 两当县| 新乡县| 文山县| 武山县| 宕昌县| 石泉县| 武清区| 颍上县| 锡林郭勒盟| 原平市| 怀化市| 马龙县| 保山市| 达州市| 维西| 教育| 桐柏县| 江津市| 迭部县| 墨竹工卡县| 台南市| 通州区| 石棉县| 瑞昌市| 平江县| 庐江县| 沧州市| 汽车| 依安县| 南阳市| 晋中市| 中卫市| 潞西市| 松原市| 长葛市| 临城县|