溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

使用python怎么編寫一個銀行賬戶系統

發布時間:2021-02-22 15:05:05 來源:億速云 閱讀:369 作者:Leah 欄目:開發技術

今天就跟大家聊聊有關使用python怎么編寫一個銀行賬戶系統,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結了以下內容,希望大家根據這篇文章可以有所收獲。

python可以做什么

Python是一種編程語言,內置了許多有效的工具,Python幾乎無所不能,該語言通俗易懂、容易入門、功能強大,在許多領域中都有廣泛的應用,例如最熱門的大數據分析,人工智能,Web開發等。

import math
import re

def main(): # 主函數
 select = True
 while (select):
 menu()
 start_int = input("請選擇你您想要操作功能的序號:")
 if start_int == "12":
  select = False
  print("你已經退出系統歡迎下次在來")
 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========銀行存取錢系統========")
 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): # 創建文件方法
 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 # 是否繼續添加
 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("輸入無效,不是輸入整型數,請重新輸入")
  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() # 讀取全部內容
 for list in Bank:
 d = dict(eval(list)) # 字符轉化為字典
 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() # 讀取全部內容
  for list in Bank:
  d = dict(eval(list)) # 字符轉化為字典
  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)) # 字符轉化為字典
   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("您的個人信息已經注銷")

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

def revise(): # 修改個人賬戶方法
 cz = []
 global g_select
 if g_select == 1:
 username = input("請輸入您的用戶名:")
 userpassword = input("請輸入您的密碼:")
 file = open(filename, 'r')
 Bank = file.readlines() # 讀取全部內容
 for list in Bank:
  d = dict(eval(list)) # 字符轉化為字典
  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)) # 字符轉化為字典
   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() # 讀取全部內容
 for list in Bank:
  d = dict(eval(list)) # 字符轉化為字典
  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)) # 字符轉化為字典
   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() # 讀取全部內容
 for list in Bank:
  d = dict(eval(list)) # 字符轉化為字典
  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)) # 字符轉化為字典
   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("請你輸入整數年份!")
 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__":

運行圖片:

使用python怎么編寫一個銀行賬戶系統

使用python怎么編寫一個銀行賬戶系統

使用python怎么編寫一個銀行賬戶系統

使用python怎么編寫一個銀行賬戶系統

使用python怎么編寫一個銀行賬戶系統

使用python怎么編寫一個銀行賬戶系統

看完上述內容,你們對使用python怎么編寫一個銀行賬戶系統有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注億速云行業資訊頻道,感謝大家的支持。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女