python實(shí)現(xiàn)銀行賬戶(hù)系統(tǒng)
Python編寫(xiě)一個(gè)簡(jiǎn)易銀行賬戶(hù)系統(tǒng),供大家參考,具體內(nèi)容如下
文章中主要涉及的方法是Python中的open(filename, ‘r')以讀的方式打開(kāi)文件open(filename, ‘w')以寫(xiě)的方式打開(kāi)文件我們用for * in *讀取文件中的數(shù)據(jù)或者寫(xiě)入文件數(shù)據(jù) 用dict(eval(list2))方法來(lái)把字符串轉(zhuǎn)化為字典。
詳細(xì)代碼如下
import math
import re
def main(): # 主函數(shù)
select = True
while (select):
menu()
start_int = input("請(qǐng)選擇你您想要操作功能的序號(hào):")
if start_int == "12":
select = False
print("你已經(jīng)退出系統(tǒng)歡迎下次在來(lái)")
elif start_int == "4":
insert()
elif start_int == "5":
login()
elif start_int == "6":
show()
elif start_int == "11":
delete()
elif start_int == "7":
revise()
elif start_int == "8":
deposit()
elif start_int == "9":
getMoney()
elif start_int == "10":
UseMoney()
def menu(): # 菜單顯示
print("1========銀行存取錢(qián)系統(tǒng)========")
print("2===========================")
print("3===========功能菜單===========")
print("4=========注冊(cè)個(gè)人信息==========")
print("5============登入=============")
print("6=========查詢(xún)個(gè)人信息==========")
print("7=========修改個(gè)人賬戶(hù)==========")
print("8============存錢(qián)=============")
print("9============取錢(qián)=============")
print("10=========顯示年收益==========")
print("11========注銷(xiāo)個(gè)人信息==========")
print("12===========退出=============")
filename = "Bank.txt" # 定義保存用戶(hù)信息的文件名
def save(Bank): # 創(chuàng)建文件方法
try:
Bank_txt = open(filename, "a")
except Exception as e:
Bank_txt = open(filename, "w")
for info in Bank:
Bank_txt.write(str(info) + "\n")
Bank_txt.close()
def insert(): # 注冊(cè)方法
BankList = [] # 保存用戶(hù)信息列表
mark = True # 是否繼續(xù)添加
while mark:
id = input("請(qǐng)輸入您的ID密碼(如1001):")
if not id:
break
name = input("請(qǐng)輸入姓名")
if not name:
break
try:
deposit = int(input("輸入你要存款的金額"))
if deposit == 0:
break
except:
print("輸入無(wú)效,不是輸入整型數(shù),請(qǐng)重新輸入")
continue
Bank = {"id": id, "name": name, "deposit": deposit}
BankList.append(Bank)
mark = False
save(BankList)
print("注冊(cè)成功")
global g_select
g_select = 0
global Username
global Userpassword
def login(): # 登入方法
global Username
global g_select
global g_BankQuery
global Userpassword
g_BankQuery = []
Username = str(input("請(qǐng)輸入您的用戶(hù)名"))
Userpassword = str(input("請(qǐng)輸入您的密碼"))
file = open(filename, 'r')
Bank = file.readlines() # 讀取全部?jī)?nèi)容
for list in Bank:
d = dict(eval(list)) # 字符轉(zhuǎn)化為字典
if d['name'] == Username and d['id'] == Userpassword:
g_BankQuery.append(d)
print("登入成功!")
g_select = 1
else:
pass
if not g_BankQuery:
g_select = 0
print("登入失敗請(qǐng)先注冊(cè)!")
else:
pass
def show(): # 查詢(xún)個(gè)人信息
if g_select == 1:
format_title = "{:^6}{:^12}"
print(format_title.format("名字", "存款"))
format_date = "{:^6}{:^12}"
for info in g_BankQuery:
print(format_date.format(str(info.get('name')), str(info.get('deposit'))))
else:
print("請(qǐng)先登入!")
def delete(): # 刪除個(gè)人賬戶(hù)方法
global g_BankQuery
cz = []
global g_select
choose = 0
if g_select == 1:
while choose < 3:
username = str(input("請(qǐng)輸入你姓名"))
userpassword = str(input("請(qǐng)輸入您的密碼"))
file = open(filename, 'r')
Bank = file.readlines() # 讀取全部?jī)?nèi)容
for list in Bank:
d = dict(eval(list)) # 字符轉(zhuǎn)化為字典
if d['name'] == username and d['id'] == userpassword:
cz.append(d)
file.close()
choose = 3
NewBank = open(filename, 'w') # 以寫(xiě)的方式打開(kāi)文件
for list2 in Bank:
d2 = dict(eval(list2)) # 字符轉(zhuǎn)化為字典
if d2['name'] != username and d2['id'] != userpassword:
NewBank.write(str(d2) + "\n")
else:
pass
else:
pass
if not cz:
choose = choose + 1
if choose == 3:
g_select = 0
print("請(qǐng)重新登入!")
else:
print("用戶(hù)名或者密碼錯(cuò)誤,請(qǐng)重新輸入你還有:" + str(3 - choose) + "機(jī)會(huì)")
else:
g_BankQuery.clear()
g_select = 0
print("您的個(gè)人信息已經(jīng)注銷(xiāo)")
else:
print("請(qǐng)先登入!")
def revise(): # 修改個(gè)人賬戶(hù)方法
cz = []
global g_select
if g_select == 1:
username = input("請(qǐng)輸入您的用戶(hù)名:")
userpassword = input("請(qǐng)輸入您的密碼:")
file = open(filename, 'r')
Bank = file.readlines() # 讀取全部?jī)?nèi)容
for list in Bank:
d = dict(eval(list)) # 字符轉(zhuǎn)化為字典
if d['name'] == username and d['id'] == userpassword:
cz.append(d)
file.close()
NewBank = open(filename, 'w') # 以寫(xiě)的方式打開(kāi)文件
for list2 in Bank:
d2 = dict(eval(list2)) # 字符轉(zhuǎn)化為字典
if d2['name'] == username and d2['id'] == userpassword:
d2['name'] = input("輸入您的新名字:")
d2['id'] = input("輸入您的新密碼:")
NewBank.write(str(d2) + "\n")
print("修改成功,請(qǐng)重新登入!")
g_select = 0
else:
NewBank.write(str(d2) + "\n")
else:
pass
if not cz:
print("你輸入的密碼或者用戶(hù)名有誤請(qǐng)重新登入")
g_select = 0
else:
pass
else:
print("請(qǐng)先登入!")
def deposit(): # 存錢(qián)方法
global g_BankQuery
global g_select
cz = []
if g_select == 1:
money = int(input("請(qǐng)輸入你要存多少錢(qián):"))
file = open(filename, 'r')
Bank = file.readlines() # 讀取全部?jī)?nèi)容
for list in Bank:
d = dict(eval(list)) # 字符轉(zhuǎn)化為字典
if d['name'] == Username and d['id'] == Userpassword:
cz.append(d)
file.close()
NewBank = open(filename, 'w') # 以寫(xiě)的方式打開(kāi)文件
for list2 in Bank:
d2 = dict(eval(list2)) # 字符轉(zhuǎn)化為字典
if d2['name'] == Username and d2['id'] == Userpassword:
d2['deposit'] = str(int(d2['deposit']) + money)
NewBank.write(str(d2) + "\n")
print("儲(chǔ)存成功!")
g_BankQuery.clear()
g_BankQuery.append(d2)
else:
NewBank.write(str(d2) + "\n")
else:
pass
else:
print("請(qǐng)先登入!")
def getMoney(): # 取錢(qián)方法
global g_select
global g_BankQuery
cz = []
if g_select == 1:
money = int(input("請(qǐng)輸入你要取多少錢(qián):"))
file = open(filename, 'r')
Bank = file.readlines() # 讀取全部?jī)?nèi)容
for list in Bank:
d = dict(eval(list)) # 字符轉(zhuǎn)化為字典
if d['name'] == Username and d['id'] == Userpassword:
cz.append(d)
if money > int(d['deposit']):
print("您的余額不足")
else:
file.close()
NewBank = open(filename, 'w') # 以寫(xiě)的方式打開(kāi)文件
for list2 in Bank:
d2 = dict(eval(list2)) # 字符轉(zhuǎn)化為字典
if d2['name'] == Username and d2['id'] == Userpassword:
d2['deposit'] = str(int(d2['deposit']) - money)
NewBank.write(str(d2) + "\n")
print("取錢(qián)成功!")
g_BankQuery.clear()
g_BankQuery.append(d2)
else:
NewBank.write(str(d2) + "\n")
else:
pass
else:
print("請(qǐng)先登入!")
def UseMoney(): # 利息計(jì)算
UM = True
while UM:
try:
money = float(input("請(qǐng)輸入你要投資理財(cái)多少錢(qián):"))
year = int(input("請(qǐng)你輸入你要儲(chǔ)存多少年:"))
except:
print("請(qǐng)你輸入整數(shù)年份!")
if 0 < year <= 3:
profitmargin = 0.03
elif 3 < year <= 5:
profitmargin = 0.04
elif 5 < year <= 10:
profitmargin = 0.06
elif year > 10:
profitmargin = 0.08
if money < 0 or year <= 0:
print("您的本金不能少于0元或者年份不能少于0年")
else:
UM = False
profit = round(money * year * profitmargin, 3)
print("你儲(chǔ)存:" + str(year) + "年將獲得的利潤(rùn)會(huì)等于:" + str(profit) + "元本金加利潤(rùn)會(huì)等于:" + str(profit + money) + "元")
if __name__ =="__main__":
運(yùn)行圖片:






以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- python實(shí)現(xiàn)銀行實(shí)戰(zhàn)系統(tǒng)
- Python實(shí)現(xiàn)銀行賬戶(hù)資金交易管理系統(tǒng)
- python銀行系統(tǒng)實(shí)現(xiàn)源碼
- python實(shí)現(xiàn)簡(jiǎn)單銀行管理系統(tǒng)
- Python銀行系統(tǒng)實(shí)戰(zhàn)源碼
- python實(shí)現(xiàn)銀行管理系統(tǒng)
- Python實(shí)現(xiàn)的銀行系統(tǒng)模擬程序完整案例
- Python3 適合初學(xué)者學(xué)習(xí)的銀行賬戶(hù)登錄系統(tǒng)實(shí)例
相關(guān)文章
pytorch模型轉(zhuǎn)換為onnx可視化(使用netron)
netron 是一個(gè)非常好用的網(wǎng)絡(luò)結(jié)構(gòu)可視化工具,但是netron對(duì)pytorch模型的支持還不成熟,這篇文章主要介紹了pytorch模型轉(zhuǎn)換為onnx,并使用netron可視化,需要的朋友可以參考下2023-05-05
Python+Tableau廣東省人口普查可視化的實(shí)現(xiàn)
本文將結(jié)合實(shí)例代碼,介紹Python+Tableau廣東省人口普查可視化,第七次人口普查數(shù)據(jù)分析,繪制歷次人口普查人口數(shù)量變化圖,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-06-06
PyQt5實(shí)現(xiàn)簡(jiǎn)易計(jì)算器
這篇文章主要為大家詳細(xì)介紹了用PyQt5開(kāi)發(fā)一個(gè)簡(jiǎn)易的計(jì)算器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-03-03
Python+selenium實(shí)現(xiàn)截圖圖片并保存截取的圖片
這篇文章介紹如何利用Selenium的方法進(jìn)行截圖并保存截取的圖片,需要的朋友參考下本文2018-01-01
基于Python輕松制作一個(gè)股票K線圖網(wǎng)站
在當(dāng)今這個(gè)人手一個(gè)?Web?服務(wù)的年代,GUI?程序還是沒(méi)有?Web?服務(wù)來(lái)的香啊。所以本文將用Python制作一個(gè)簡(jiǎn)單的股票K線圖網(wǎng)站,感興趣的可以了解一下2022-09-09

