模擬實現一個ATM + 購物商城程序
-
額度 15000或自定義
-
實現購物商城,買東西加入 購物車,調用信用卡接口結帳
-
能夠提現,手續費5%
-
每個月22號出帳單,每個月10號爲還款日,過時未還,按欠款總額 萬分之5 每日計息
-
支持多帳戶登陸
-
支持帳戶間轉帳
-
記錄每個月平常消費流水
-
提供還款接口
-
ATM記錄操做日誌
-
提供管理接口,包括添加帳戶、用戶額度,凍結帳戶等。。。
-
用戶認證用裝飾器
# import time
import datetime
# time.time() # 當前時間戳
# datetime.datetime.now() # 本地之間
# 數據處理=====================================
# 所有用戶數據
user_data = []
# 加載數據到內存
def load_data():
f = open("DB/user_db.txt","rt",encoding="utf-8")
for line in f:
line = line.strip("\n")
if line == "\n":continue
ls = line.split("|")
usr_dic = {"name":ls[0],
"pwd":ls[1],
"max": ls[2],
"money": ls[3],
"lock": ls[4]}
user_data.append(usr_dic)
f.close()
# 根據帳戶名獲取一個用戶
def get_usr(name):
for usr in user_data:
if usr["name"] == name:
return usr
# 將內存中的數據持久存儲到文件中
def save_to_file():
f = open("DB/user_db.txt","wt",encoding="utf-8")
for usr in user_data:
text = "|".join(usr.values())
text += "\n"
f.write(text)
f.close()
# 數據處理=====================================
# 登陸驗證裝飾器(閉包函數) (再不改變源代碼的調用方式基礎上 爲這個函數添加新功能)
def login_auth(func):
def wrapper(*args,**kwargs):
# 驗證是否登錄過了
if current_usr == None:
print("請先登陸!")
atm_login()
if current_usr:
return func(*args,**kwargs)
else:
return func(*args,**kwargs)
return wrapper
# 購物中心========================================
# 商品信息
products = [{"name":"挨糞叉","price":6888},
{"name":"錘子TNT","price":10888},
{"name":"小米mix2","price":2888}]
# 購物車
car = {}
# 購物
def shopping():
while True:
# 打印出全部商品信息
count = 1
for p in products:
print("序號:%-3s 名稱:%-10s 價格:%-6s" % (count,p["name"],p["price"]))
count += 1
select = input("親輸入商品的序號q退出:\n")
if select == "q":
return
if select.isdigit() and int(select) >= 1 and int(select) <= len(products):
pd = products[int(select)-1]
print("%s已成功加入購物車!" % pd["name"])
# 判斷商品是否已經存在於購物車
if pd["name"] in car:
car[pd["name"]]["count"] += 1
else:
car[pd["name"]] = {"price":pd["price"],"count":1}
else:
print("輸入有誤請從新輸入!")
# 查看購物車
def show_cars():
if not car:
s = input("你的購物車是空的! 你要買點什麼嗎? y/n")
if s == "y":
shopping()
return
else:
return
print("您的購物車信息:")
for p in car:
print("名稱:%-10s 價格:%-8s 數量:%-3s 總價:%-10s" % (p,
car[p]["price"],
car[p]["count"],
car[p]["price"] * car[p]["count"]))
select = input("輸入y調整商品數量!(數量爲0則刪除商品!) 輸入其餘退出!")
if select == "y":
modify_count()
# 調整購物車中的商品數量
def modify_count():
while True:
name = input("請輸入商品名稱q退出:\n")
if name == "q":
return
if name not in car:
print("輸入不正確請重試!")
continue
while True:
count = input("輸入調整後數量:\n")
if not count.isdigit():
print("數量不正確 必須是整數!")
continue
count = int(count)
if count == 0:
car.pop(name)
print("%s已刪除" % name)
return
else:
car[name]["count"] = count
print("修改爲功!")
return
# 結算
@login_auth
def pay_cars():
# 計算商品總價格
sum = 0
for p in car:
sum += car[p]["price"] * car[p]["count"]
print("您的訂單總價爲:%s元" % sum)
if paymoney(sum):
print("剁手成功! 回家等着吧!")
clear_cars()
# 清空購物車
def clear_cars():
car.clear()
print("購物車已清空!")
def shop_center():
shopfuncs = {"1":shopping,"2":show_cars,"3":pay_cars,"4":clear_cars}
while True:
print("""
1.購物
2.查看購物車
3.結算
4.清空
q.退出""")
index = input("請選擇:\n").strip()
if index == "q":
return
if index in shopfuncs:
shopfuncs[index]()
else:
print("輸入不正確!請重試!")
# 購物中心========================================
# ATM====================================================
# 用於保存登陸成功的用戶信息
current_usr = None
# 日誌裝飾器.
# 日誌文件
atmlog_file = open("DB/log.txt","at",encoding="utf-8")
# 用戶流水文件
moneyflow = None
def atm_logger(func):
def wrapper(*args,**kwargs):
res = func(*args,**kwargs)
# 記錄日誌
atmlog_file.write("[%s] user:%s function:%s\n" % (datetime.datetime.now(),current_usr["name"],func.__name__))
atmlog_file.flush() # 當即刷出緩存區的數據到硬盤 若是每次write都操做一次硬盤
# 效率很是低 因此python內置了緩衝區 只有當緩衝區滿了纔會寫入硬盤 一次來下降硬盤操做次數
return wrapper
# 登陸
def atm_login():
while True:
name = input("請輸入帳戶名:(q退出)\n").strip()
# 手動記錄日誌 由於用戶尚未登錄
atmlog_file.write("[%s] user:%s function:%s\n" % (datetime.datetime.now(), name, atm_login.__name__))
atmlog_file.flush()
if name == "q":
return
if not name:
print("用戶名不能爲空!")
continue
usr = get_usr(name)
if not usr:
print("用戶名不存在!")
continue
pwd = input("請輸入密碼:\n").strip()
if not pwd:
print("密碼不能爲空!")
continue
if name == usr["name"] and pwd == usr["pwd"]:
print("登陸成功")
global current_usr,moneyflow
# 打開流水文件
moneyflow = open("DB/%s.txt" % name,"at",encoding="utf-8")
# 記錄當前登陸用戶信息
current_usr = usr
return
else:
print("帳戶名或密碼不正確!請重試!")
# 提現
@login_auth
@atm_logger
def withdraw():
while True:
print("當前餘額:%s元" % current_usr["money"])
money = input("請輸入提款金額:(整數 q退出)\n")
if money == "q":return
if not money.isdigit():
print("輸入有誤!請重試!")
continue
money = int(money)
# 手續費
opt = money * 0.05
print("須要手續費%s元" % opt)
usr_moeny = float(current_usr["money"])
if money+opt > usr_moeny:
print("餘額不足!很尷尬")
continue
current_usr["money"] = str(usr_moeny - money - opt)
save_to_file()
print("請提取你的鈔票!")
moneyflow.write("[%s] 帳戶:%s 提現%s元 餘額%s元\n" % (datetime.datetime.now(),
current_usr["name"],
money,
current_usr["money"]))
moneyflow.flush()
return
# 轉帳
@login_auth
@atm_logger
def transfer():
while True:
account = input("請輸入對方的帳戶名:\n")
to_usr = get_usr(account)
if not to_usr:
print("帳戶不存在 請從新輸入!")
continue
print("當前餘額:%s元" % current_usr["money"])
money = input("請輸入轉帳金額:(整數 q退出)\n")
if money == "q": return
money = str_to_num(money)
if not money:
print("輸入有誤!請重試!")
continue
usr_moeny = float(current_usr["money"])
if money > usr_moeny:
print("餘額不足!很尷尬")
continue
# 原始帳戶減去
current_usr["money"] = str(usr_moeny - money)
# 目標帳戶加上
to_usr["money"] = str(float(to_usr["money"]) + money)
save_to_file()
print("轉帳成功!")
moneyflow.write("[%s] 帳戶:%s 轉帳%s元 給%s 餘額%s元\n" % (datetime.datetime.now(),
current_usr["name"],
money,
account,
current_usr["money"]))
moneyflow.flush()
return
# 將字符串轉成數字 "11212101.s"
def str_to_num(text):
if text.isdigit():
return int(text)
if "." in text:
ts = text.split(".")
if len(ts) == 2:
if ts[0].isdigit() and ts[1].isdigit():
return float(text)
# 還款
@login_auth
@atm_logger
def repayment():
print("您當前欠款:%s" % (str_to_num(current_usr["max"]) - str_to_num(current_usr["money"])))
while True:
print("repayment")
money = input("請輸入還款金額!q退出:\n")
if money == "q":return
money = str_to_num(money)
if not money:
print("輸入有誤 請重試!")
continue
current_usr["money"] = str(str_to_num(current_usr["money"]) + money)
save_to_file()
print("還款成功!")
moneyflow.write("[%s] 帳戶:%s 還款%s元 餘額%s元\n" % (datetime.datetime.now(),
current_usr["name"],
money,
current_usr["money"]))
moneyflow.flush()
return
# 結算 須要傳入訂單總價格
@login_auth
@atm_logger
def paymoney(price):
if price > str_to_num(current_usr["money"]):
print("額度不足!又尷尬了")
else:
current_usr["money"] = str(str_to_num(current_usr["money"]) - price)
save_to_file()
print("結算成功!")
moneyflow.write("[%s] 帳戶:%s 購物消費%s元 餘額%s元\n" % (datetime.datetime.now(),
current_usr["name"],
price,
current_usr["money"]))
moneyflow.flush()
return True
def atm():
atm_funcs = {"1": atm_login, "2": withdraw, "3": transfer, "4": repayment}
while True:
print("""
1.登陸
2.提現
3.轉帳
4.還款
(q.退出!)""")
index = input("請選擇:\n")
if index == "q":
# 清空當前用戶信息 關閉流水文件
global current_usr
if current_usr:
current_usr = None
moneyflow.close()
return
if index in atm_funcs:
atm_funcs[index]()
else:
print("輸入有誤請重試!")
# ATM====================================================
# 管理員接口=============================================
# 顯示全部的用戶信息 並從中選擇一個用戶
def show_users_and_select():
while True:
for usr in user_data:
print("%-10s %-10s %-10s %-2s" % (usr["name"],usr["max"],usr["money"],usr["lock"]))
select = input("請選擇一個用戶(輸入用戶名:q退出)\n")
if select == "q":
return
for u in user_data:
if select == u["name"]:
return u
else:
print("輸入不正確 請從新輸入!")
# 管理員登陸
def admin_login():
while True:
name = input("請輸入管理員帳戶名:(q退出)\n").strip()
if name == "q":
return
if not name:
print("用戶名不能爲空!")
continue
pwd = input("請輸入管理員密碼:\n").strip()
if not pwd:
print("密碼不能爲空!")
continue
if name == "admin" and pwd == "123":
print("登陸成功")
return True
else:
print("帳戶名或密碼不正確!請重試!")
#添加帳戶
def create_user():
while True:
name = input("請輸入帳戶名:(q退出)\n").strip()
if name == "q":
return
if not name:
print("用戶名不能爲空!")
continue
# 獲取用戶 經過帳戶名
usr = get_usr(name)
if usr:
print("用戶名已經存在,請重試!")
continue
pwd = input("請輸入密碼:\n").strip()
if not pwd:
print("密碼不能爲空!")
continue
if pwd != input("請再次輸入密碼:").strip():
print("兩次密碼不相同請重試!")
continue
# 將用戶輸入的信息打包成字典 存到列表中
new_usr = {"name":name,"pwd":pwd,"max":"15000","money":"500","lock":"0"}
user_data.append(new_usr)
print("建立成功!")
# 持久化存儲......
save_to_file()
return
#調整額度
def modify_amount():
# 先選擇一個用戶
usr = show_users_and_select()
if not usr:
return
while True:
# 輸入新的額度
new_max = input("請輸入新的額度:(q退出)\n").strip()
if new_max == "q":
return
if not new_max.isdigit():
print("輸入不正確 請從新輸入!")
continue
usr["max"] = new_max
save_to_file()
print("修改爲功!")
return
#凍結帳戶
def lock_user():
# 先選擇一個用戶
usr = show_users_and_select()
if not usr:
print("取消操做!")
return
usr["lock"] = "1"
save_to_file()
print("凍結成功!")
#解凍帳戶
def unlock_user():
# 先選擇一個用戶
usr = show_users_and_select()
if not usr:
print("取消操做!")
return
usr["lock"] = "0"
save_to_file()
print("解凍成功!")
# 管理員接口界面
def admin_view():
# 調用登陸功能驗證是否有權限執行操做
if not admin_login():
return
admin_funcs = {"1":create_user,"2":modify_amount,"3":lock_user,"4":unlock_user}
while True:
print("""
1.添加帳戶
2.修改額度
3.凍結帳戶
4.解凍帳戶
(q.退出!)""")
index = input("請選擇:\n")
if index == "q":
return
if index in admin_funcs:
admin_funcs[index]()
else:
print("輸入有誤請重試!")
# 管理員接口=============================================
# 程序的入口函數
def run():
print("welcome to oldboy ATM system!")
# 將函數裝到字典中 用序號做爲key 方便判斷
funcs = {"1": shop_center, "2": atm, "3": admin_view}
while True:
print("""
1.購物中心
2.ATM
3.管理員接口
(q.退出!)""")
index = input("請選擇:\n")
if index == "q":
print("下次再見!")
return
if index in funcs:
funcs[index]()
else:
print("輸入有誤請重試!")
# 啓動系統
load_data()
run()
atmlog_file.close()
# print(user_data)
# print(str_to_num("100.s"))
# import time
import datetime
# time.time() # 當前時間戳
# datetime.datetime.now() # 本地之間
# 數據處理=====================================
# 所有用戶數據
user_data = []
# 加載數據到內存
def load_data():
f = open("DB/user_db.txt","rt",encoding="utf-8")
for line in f:
line = line.strip("\n")
if line == "\n":continue
ls = line.split("|")
usr_dic = {"name":ls[0],
"pwd":ls[1],
"max": ls[2],
"money": ls[3],
"lock": ls[4]}
user_data.append(usr_dic)
f.close()
# 根據帳戶名獲取一個用戶
def get_usr(name):
for usr in user_data:
if usr["name"] == name:
return usr
# 將內存中的數據持久存儲到文件中
def save_to_file():
f = open("DB/user_db.txt","wt",encoding="utf-8")
for usr in user_data:
text = "|".join(usr.values())
text += "\n"
f.write(text)
f.close()
# 數據處理=====================================
# 登陸驗證裝飾器(閉包函數) (再不改變源代碼的調用方式基礎上 爲這個函數添加新功能)
def login_auth(func):
def wrapper(*args,**kwargs):
# 驗證是否登錄過了
if current_usr == None:
print("請先登陸!")
atm_login()
if current_usr:
return func(*args,**kwargs)
else:
return func(*args,**kwargs)
return wrapper
# 購物中心========================================
# 商品信息
products = [{"name":"挨糞叉","price":6888},
{"name":"錘子TNT","price":10888},
{"name":"小米mix2","price":2888}]
# 購物車
car = {}
# 購物
def shopping():
while True:
# 打印出全部商品信息
count = 1
for p in products:
print("序號:%-3s 名稱:%-10s 價格:%-6s" % (count,p["name"],p["price"]))
count += 1
select = input("親輸入商品的序號q退出:\n")
if select == "q":
return
if select.isdigit() and int(select) >= 1 and int(select) <= len(products):
pd = products[int(select)-1]
print("%s已成功加入購物車!" % pd["name"])
# 判斷商品是否已經存在於購物車
if pd["name"] in car:
car[pd["name"]]["count"] += 1
else:
car[pd["name"]] = {"price":pd["price"],"count":1}
else:
print("輸入有誤請從新輸入!")
# 查看購物車
def show_cars():
if not car:
s = input("你的購物車是空的! 你要買點什麼嗎? y/n")
if s == "y":
shopping()
return
else:
return
print("您的購物車信息:")
for p in car:
print("名稱:%-10s 價格:%-8s 數量:%-3s 總價:%-10s" % (p,
car[p]["price"],
car[p]["count"],
car[p]["price"] * car[p]["count"]))
select = input("輸入y調整商品數量!(數量爲0則刪除商品!) 輸入其餘退出!")
if select == "y":
modify_count()
# 調整購物車中的商品數量
def modify_count():
while True:
name = input("請輸入商品名稱q退出:\n")
if name == "q":
return
if name not in car:
print("輸入不正確請重試!")
continue
while True:
count = input("輸入調整後數量:\n")
if not count.isdigit():
print("數量不正確 必須是整數!")
continue
count = int(count)
if count == 0:
car.pop(name)
print("%s已刪除" % name)
return
else:
car[name]["count"] = count
print("修改爲功!")
return
# 結算
@login_auth
def pay_cars():
# 計算商品總價格
sum = 0
for p in car:
sum += car[p]["price"] * car[p]["count"]
print("您的訂單總價爲:%s元" % sum)
if paymoney(sum):
print("剁手成功! 回家等着吧!")
clear_cars()
# 清空購物車
def clear_cars():
car.clear()
print("購物車已清空!")
def shop_center():
shopfuncs = {"1":shopping,"2":show_cars,"3":pay_cars,"4":clear_cars}
while True:
print("""
1.購物
2.查看購物車
3.結算
4.清空
q.退出""")
index = input("請選擇:\n").strip()
if index == "q":
return
if index in shopfuncs:
shopfuncs[index]()
else:
print("輸入不正確!請重試!")
# 購物中心========================================
# ATM====================================================
# 用於保存登陸成功的用戶信息
current_usr = None
# 日誌裝飾器.
# 日誌文件
atmlog_file = open("DB/log.txt","at",encoding="utf-8")
# 用戶流水文件
moneyflow = None
def atm_logger(func):
def wrapper(*args,**kwargs):
res = func(*args,**kwargs)
# 記錄日誌
atmlog_file.write("[%s] user:%s function:%s\n" % (datetime.datetime.now(),current_usr["name"],func.__name__))
atmlog_file.flush() # 當即刷出緩存區的數據到硬盤 若是每次write都操做一次硬盤
# 效率很是低 因此python內置了緩衝區 只有當緩衝區滿了纔會寫入硬盤 一次來下降硬盤操做次數
return wrapper
# 登陸
def atm_login():
while True:
name = input("請輸入帳戶名:(q退出)\n").strip()
# 手動記錄日誌 由於用戶尚未登錄
atmlog_file.write("[%s] user:%s function:%s\n" % (datetime.datetime.now(), name, atm_login.__name__))
atmlog_file.flush()
if name == "q":
return
if not name:
print("用戶名不能爲空!")
continue
usr = get_usr(name)
if not usr:
print("用戶名不存在!")
continue
pwd = input("請輸入密碼:\n").strip()
if not pwd:
print("密碼不能爲空!")
continue
if name == usr["name"] and pwd == usr["pwd"]:
print("登陸成功")
global current_usr,moneyflow
# 打開流水文件
moneyflow = open("DB/%s.txt" % name,"at",encoding="utf-8")
# 記錄當前登陸用戶信息
current_usr = usr
return
else:
print("帳戶名或密碼不正確!請重試!")
# 提現
@login_auth
@atm_logger
def withdraw():
while True:
print("當前餘額:%s元" % current_usr["money"])
money = input("請輸入提款金額:(整數 q退出)\n")
if money == "q":return
if not money.isdigit():
print("輸入有誤!請重試!")
continue
money = int(money)
# 手續費
opt = money * 0.05
print("須要手續費%s元" % opt)
usr_moeny = float(current_usr["money"])
if money+opt > usr_moeny:
print("餘額不足!很尷尬")
continue
current_usr["money"] = str(usr_moeny - money - opt)
save_to_file()
print("請提取你的鈔票!")
moneyflow.write("[%s] 帳戶:%s 提現%s元 餘額%s元\n" % (datetime.datetime.now(),
current_usr["name"],
money,
current_usr["money"]))
moneyflow.flush()
return
# 轉帳
@login_auth
@atm_logger
def transfer():
while True:
account = input("請輸入對方的帳戶名:\n")
to_usr = get_usr(account)
if not to_usr:
print("帳戶不存在 請從新輸入!")
continue
print("當前餘額:%s元" % current_usr["money"])
money = input("請輸入轉帳金額:(整數 q退出)\n")
if money == "q": return
money = str_to_num(money)
if not money:
print("輸入有誤!請重試!")
continue
usr_moeny = float(current_usr["money"])
if money > usr_moeny:
print("餘額不足!很尷尬")
continue
# 原始帳戶減去
current_usr["money"] = str(usr_moeny - money)
# 目標帳戶加上
to_usr["money"] = str(float(to_usr["money"]) + money)
save_to_file()
print("轉帳成功!")
moneyflow.write("[%s] 帳戶:%s 轉帳%s元 給%s 餘額%s元\n" % (datetime.datetime.now(),
current_usr["name"],
money,
account,
current_usr["money"]))
moneyflow.flush()
return
# 將字符串轉成數字 "11212101.s"
def str_to_num(text):
if text.isdigit():
return int(text)
if "." in text:
ts = text.split(".")
if len(ts) == 2:
if ts[0].isdigit() and ts[1].isdigit():
return float(text)
# 還款
@login_auth
@atm_logger
def repayment():
print("您當前欠款:%s" % (str_to_num(current_usr["max"]) - str_to_num(current_usr["money"])))
while True:
print("repayment")
money = input("請輸入還款金額!q退出:\n")
if money == "q":return
money = str_to_num(money)
if not money:
print("輸入有誤 請重試!")
continue
current_usr["money"] = str(str_to_num(current_usr["money"]) + money)
save_to_file()
print("還款成功!")
moneyflow.write("[%s] 帳戶:%s 還款%s元 餘額%s元\n" % (datetime.datetime.now(),
current_usr["name"],
money,
current_usr["money"]))
moneyflow.flush()
return
# 結算 須要傳入訂單總價格
@login_auth
@atm_logger
def paymoney(price):
if price > str_to_num(current_usr["money"]):
print("額度不足!又尷尬了")
else:
current_usr["money"] = str(str_to_num(current_usr["money"]) - price)
save_to_file()
print("結算成功!")
moneyflow.write("[%s] 帳戶:%s 購物消費%s元 餘額%s元\n" % (datetime.datetime.now(),
current_usr["name"],
price,
current_usr["money"]))
moneyflow.flush()
return True
def atm():
atm_funcs = {"1": atm_login, "2": withdraw, "3": transfer, "4": repayment}
while True:
print("""
1.登陸
2.提現
3.轉帳
4.還款
(q.退出!)""")
index = input("請選擇:\n")
if index == "q":
# 清空當前用戶信息 關閉流水文件
global current_usr
if current_usr:
current_usr = None
moneyflow.close()
return
if index in atm_funcs:
atm_funcs[index]()
else:
print("輸入有誤請重試!")
# ATM====================================================
# 管理員接口=============================================
# 顯示全部的用戶信息 並從中選擇一個用戶
def show_users_and_select():
while True:
for usr in user_data:
print("%-10s %-10s %-10s %-2s" % (usr["name"],usr["max"],usr["money"],usr["lock"]))
select = input("請選擇一個用戶(輸入用戶名:q退出)\n")
if select == "q":
return
for u in user_data:
if select == u["name"]:
return u
else:
print("輸入不正確 請從新輸入!")
# 管理員登陸
def admin_login():
while True:
name = input("請輸入管理員帳戶名:(q退出)\n").strip()
if name == "q":
return
if not name:
print("用戶名不能爲空!")
continue
pwd = input("請輸入管理員密碼:\n").strip()
if not pwd:
print("密碼不能爲空!")
continue
if name == "admin" and pwd == "123":
print("登陸成功")
return True
else:
print("帳戶名或密碼不正確!請重試!")
#添加帳戶
def create_user():
while True:
name = input("請輸入帳戶名:(q退出)\n").strip()
if name == "q":
return
if not name:
print("用戶名不能爲空!")
continue
# 獲取用戶 經過帳戶名
usr = get_usr(name)
if usr:
print("用戶名已經存在,請重試!")
continue
pwd = input("請輸入密碼:\n").strip()
if not pwd:
print("密碼不能爲空!")
continue
if pwd != input("請再次輸入密碼:").strip():
print("兩次密碼不相同請重試!")
continue
# 將用戶輸入的信息打包成字典 存到列表中
new_usr = {"name":name,"pwd":pwd,"max":"15000","money":"500","lock":"0"}
user_data.append(new_usr)
print("建立成功!")
# 持久化存儲......
save_to_file()
return
#調整額度
def modify_amount():
# 先選擇一個用戶
usr = show_users_and_select()
if not usr:
return
while True:
# 輸入新的額度
new_max = input("請輸入新的額度:(q退出)\n").strip()
if new_max == "q":
return
if not new_max.isdigit():
print("輸入不正確 請從新輸入!")
continue
usr["max"] = new_max
save_to_file()
print("修改爲功!")
return
#凍結帳戶
def lock_user():
# 先選擇一個用戶
usr = show_users_and_select()
if not usr:
print("取消操做!")
return
usr["lock"] = "1"
save_to_file()
print("凍結成功!")
#解凍帳戶
def unlock_user():
# 先選擇一個用戶
usr = show_users_and_select()
if not usr:
print("取消操做!")
return
usr["lock"] = "0"
save_to_file()
print("解凍成功!")
# 管理員接口界面
def admin_view():
# 調用登陸功能驗證是否有權限執行操做
if not admin_login():
return
admin_funcs = {"1":create_user,"2":modify_amount,"3":lock_user,"4":unlock_user}
while True:
print("""
1.添加帳戶
2.修改額度
3.凍結帳戶
4.解凍帳戶
(q.退出!)""")
index = input("請選擇:\n")
if index == "q":
return
if index in admin_funcs:
admin_funcs[index]()
else:
print("輸入有誤請重試!")
# 管理員接口=============================================
# 程序的入口函數
def run():
print("welcome to oldboy ATM system!")
# 將函數裝到字典中 用序號做爲key 方便判斷
funcs = {"1": shop_center, "2": atm, "3": admin_view}
while True:
print("""
1.購物中心
2.ATM
3.管理員接口
(q.退出!)""")
index = input("請選擇:\n")
if index == "q":
print("下次再見!")
return
if index in funcs:
funcs[index]()
else:
print("輸入有誤請重試!")
# 啓動系統
load_data()
run()
atmlog_file.close()
# print(user_data)
# print(str_to_num("100.s"))
# 只有程序時從當前文件開始運行時才進入if語句
# if __name__ == '__main__':
# 只有程序時從當前文件開始運行時才進入if語句
# if __name__ == '__main__':