欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python實現(xiàn)銀行賬戶系統(tǒng)

 更新時間:2021年02月22日 11:29:56   作者:nanxiang11  
這篇文章主要為大家詳細介紹了python實現(xiàn)銀行賬戶系統(tǒng),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

Python編寫一個簡易銀行賬戶系統(tǒng),供大家參考,具體內(nèi)容如下

文章中主要涉及的方法是Python中的open(filename, ‘r')以讀的方式打開文件open(filename, ‘w')以寫的方式打開文件我們用for * in *讀取文件中的數(shù)據(jù)或者寫入文件數(shù)據(jù) 用dict(eval(list2))方法來把字符串轉(zhuǎn)化為字典。

詳細代碼如下

import math
import re

def main(): # 主函數(shù)
 select = True
 while (select):
 menu()
 start_int = input("請選擇你您想要操作功能的序號:")
 if start_int == "12":
 select = False
 print("你已經(jīng)退出系統(tǒng)歡迎下次在來")
 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========銀行存取錢系統(tǒng)========")
 print("2===========================")
 print("3===========功能菜單===========")
 print("4=========注冊個人信息==========")
 print("5============登入=============")
 print("6=========查詢個人信息==========")
 print("7=========修改個人賬戶==========")
 print("8============存錢=============")
 print("9============取錢=============")
 print("10=========顯示年收益==========")
 print("11========注銷個人信息==========")
 print("12===========退出=============")


filename = "Bank.txt" # 定義保存用戶信息的文件名

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(): # 注冊方法
 BankList = [] # 保存用戶信息列表
 mark = True # 是否繼續(xù)添加
 while mark:
 id = input("請輸入您的ID密碼(如1001):")
 if not id:
 break
 name = input("請輸入姓名")
 if not name:
 break
 try:
 deposit = int(input("輸入你要存款的金額"))
 if deposit == 0:
 break
 except:
 print("輸入無效,不是輸入整型數(shù),請重新輸入")
 continue
 Bank = {"id": id, "name": name, "deposit": deposit}
 BankList.append(Bank)
 mark = False
 save(BankList)
 print("注冊成功")


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("請輸入您的用戶名"))
 Userpassword = str(input("請輸入您的密碼"))
 file = open(filename, 'r')
 Bank = file.readlines() # 讀取全部內(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("登入失敗請先注冊!")
 else:
 pass




def show(): # 查詢個人信息
 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("請先登入!")


def delete(): # 刪除個人賬戶方法
 global g_BankQuery
 cz = []
 global g_select
 choose = 0
 if g_select == 1:
 while choose < 3:
 username = str(input("請輸入你姓名"))
 userpassword = str(input("請輸入您的密碼"))
 file = open(filename, 'r')
 Bank = file.readlines() # 讀取全部內(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') # 以寫的方式打開文件
  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("請重新登入!")
 else:
  print("用戶名或者密碼錯誤,請重新輸入你還有:" + str(3 - choose) + "機會")
 else:
 g_BankQuery.clear()
 g_select = 0
 print("您的個人信息已經(jīng)注銷")

 else:
 print("請先登入!")

def revise(): # 修改個人賬戶方法
 cz = []
 global g_select
 if g_select == 1:
 username = input("請輸入您的用戶名:")
 userpassword = input("請輸入您的密碼:")
 file = open(filename, 'r')
 Bank = file.readlines() # 讀取全部內(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') # 以寫的方式打開文件
 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("修改成功,請重新登入!")
  g_select = 0
  else:
  NewBank.write(str(d2) + "\n")
 else:
 pass
 if not cz:
 print("你輸入的密碼或者用戶名有誤請重新登入")
 g_select = 0
 else:
 pass
 else:
 print("請先登入!")

def deposit(): # 存錢方法
 global g_BankQuery
 global g_select
 cz = []
 if g_select == 1:
 money = int(input("請輸入你要存多少錢:"))
 file = open(filename, 'r')
 Bank = file.readlines() # 讀取全部內(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') # 以寫的方式打開文件
 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("儲存成功!")
  g_BankQuery.clear()
  g_BankQuery.append(d2)
  else:
  NewBank.write(str(d2) + "\n")
 else:
 pass
 else:
 print("請先登入!")

def getMoney(): # 取錢方法
 global g_select
 global g_BankQuery
 cz = []
 if g_select == 1:
 money = int(input("請輸入你要取多少錢:"))
 file = open(filename, 'r')
 Bank = file.readlines() # 讀取全部內(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') # 以寫的方式打開文件
  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("取錢成功!")
  g_BankQuery.clear()
  g_BankQuery.append(d2)
  else:
  NewBank.write(str(d2) + "\n")
 else:
 pass
 else:
 print("請先登入!")


def UseMoney(): # 利息計算
 UM = True
 while UM:
 try:
 money = float(input("請輸入你要投資理財多少錢:"))
 year = int(input("請你輸入你要儲存多少年:"))
 except:
 print("請你輸入整數(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("你儲存:" + str(year) + "年將獲得的利潤會等于:" + str(profit) + "元本金加利潤會等于:" + str(profit + money) + "元")


if __name__ =="__main__":

運行圖片:

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

相關(guān)文章

  • Python+OpenCV實現(xiàn)將圖像轉(zhuǎn)換為二進制格式

    Python+OpenCV實現(xiàn)將圖像轉(zhuǎn)換為二進制格式

    今天小編就為大家分享一篇Python+OpenCV實現(xiàn)將圖像轉(zhuǎn)換為二進制格式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-01-01
  • python統(tǒng)計字符串中指定字符出現(xiàn)次數(shù)的方法

    python統(tǒng)計字符串中指定字符出現(xiàn)次數(shù)的方法

    這篇文章主要介紹了python統(tǒng)計字符串中指定字符出現(xiàn)次數(shù)的方法,涉及Python中count函數(shù)的使用技巧,非常具有實用價值,需要的朋友可以參考下
    2015-04-04
  • python socket 聊天室實例代碼詳解

    python socket 聊天室實例代碼詳解

    在本篇文章里小編給大家整理了關(guān)于python socket 聊天室的相關(guān)知識點,需要的朋友們參考下。
    2019-11-11
  • 基于python實現(xiàn)刪除指定文件類型

    基于python實現(xiàn)刪除指定文件類型

    這篇文章主要介紹了基于python實現(xiàn)刪除指定文件類型,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-07-07
  • Python中的裝飾器鏈(decorator chain)詳解

    Python中的裝飾器鏈(decorator chain)詳解

    在Python中,裝飾器是一種高級功能,它允許你在不修改函數(shù)或類代碼的情況下,為它們添加額外的功能,裝飾器通常用于日志記錄、性能測量、權(quán)限檢查等場景,當多個裝飾器應(yīng)用于同一個函數(shù)或類時,形成裝飾器鏈,這篇文章主要介紹了Python中的裝飾器鏈詳解,需要的朋友可以參考下
    2024-06-06
  • Python的sqlite3模塊中常用函數(shù)

    Python的sqlite3模塊中常用函數(shù)

    sqlite3模塊是Python中的內(nèi)置模塊,用于與SQLite數(shù)據(jù)庫交互,本文就來介紹一下Python的sqlite3模塊中常用函數(shù),感興趣的可以了解一下
    2023-10-10
  • Python+PyQt5+MySQL實現(xiàn)天氣管理系統(tǒng)

    Python+PyQt5+MySQL實現(xiàn)天氣管理系統(tǒng)

    這篇文章主要為大家詳細介紹了Python+PyQt5+MySQL實現(xiàn)天氣管理系統(tǒng),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-06-06
  • 一文詳解Python中復(fù)合語句的用法

    一文詳解Python中復(fù)合語句的用法

    復(fù)合語句是包含其它語句(語句組)的語句;它們會以某種方式影響或控制所包含其它語句的執(zhí)行。通常,復(fù)合語句會跨越多行,雖然在某些簡單形式下整個復(fù)合語句也可能包含于一行之內(nèi)。本文就來講講Python中復(fù)合語句的使用
    2022-07-07
  • Python中的pprint模塊

    Python中的pprint模塊

    本文介紹了 Python中的pprint模塊,pprint模塊包含一個“美觀打印機”,用于生成數(shù)據(jù)結(jié)構(gòu)的一個美觀的視圖。格式化工具會生成數(shù)據(jù)結(jié)構(gòu)的一些表示,不僅能夠由解釋器正確地解析,還便于人閱讀。輸出會盡可能放在一行上,分解為多行時會縮進,想了解具體內(nèi)容請參考下文
    2021-11-11
  • Python計算矩陣的和積的實例詳解

    Python計算矩陣的和積的實例詳解

    在本篇內(nèi)容里小編給大家整理的是關(guān)于Python計算矩陣的和積的實例詳解內(nèi)容,需要的朋友們參考下。
    2020-09-09

最新評論