模擬實現一個ATM + 購物商城程序
1.額度 15000或自定義
2.實現購物商城,買東西加入 購物車,調用信用卡接口結賬
3.可以提現,手續費5%
4.每月22號出賬單,每月10號為還款日,過期未還,按欠款總額 萬分之5 每日計息
5.支持多賬戶登錄
6.支持賬戶間轉賬
7.記錄每月日常消費流水
8.提供還款接口
9.ATM記錄操作日志
10.提供管理接口,包括添加賬戶、用戶額度,凍結賬戶等。。。
11.用戶認證用裝飾器
功能:4,8,10 沒有實現
參數解釋:
購物車賬戶:admin 密碼:123
信用卡轉賬賬戶:xinyongka 密碼:456
流程圖:
目錄結構圖:
代碼:
start.py 模塊def?start_shop():
login()
while?True:
print?('''
#################################################################
#???????????1.購物
#???????????2.余額查詢
#???????????3.轉賬
#???????????4.還款
#???????????5.操作記錄查詢
#???????????6.賬戶流水
#???????????7.登錄后臺系統
#################################################################
''')
number=input('請輸入您要執行的操作:').strip()
if?number?==?"1":
buy_shop()
elif?number?==?"2":
time.sleep(1)
money_query()
elif?number?==?"3":
time.sleep(1)
Transfer()
elif?number?==?"4":
time.sleep(1)
huankuan()
elif?number?==?"5":
time.sleep(1)
log_sys()
elif?number?==?"6":
time.sleep(1)
monye_logs()
elif?number?==?"7":
Backstage()
else:
print?('您輸入有誤,請重新輸入:')
time.sleep(3)
start_shop()
shop.py 模塊
import time
import datetime
import os,sys
buy_shop_list=[]
shop_list= [{"name": "上衣", "price": 300},
{"name": "下衣", "price": 350},
{"name": "鞋子", "price": 270},
{"name": "帽子", "price": 150},
]
def buy_shop():
print('您的默認信用卡額度為:15000元')
wages = 15000
wages = int(wages)
print('您的賬戶額度為%s ' % wages)
# while True:
for index, item in enumerate(shop_list): #給商品列表增加序號
print ('以下是您可購買的商品列表,請輸入商品號購買')
print (index,item) ? ? ? ? ? ?#打印可以購買的商品列表
while True: ? ? ? ? ? ? ? ? ? ? # 輸入商品ID進行購買
shop_number=input('請輸入商品號: ').strip() ? ? #商品購買
shop_number=int(shop_number)
buy_shop_list.append(shop_list[shop_number]) ? ? #將購買的商品添加到購物車
buy=input('輸入Y/y繼續購買,輸入N/n進行結算: ') ? #輸入y/n是否繼續購買
if buy == 'Y' or buy == 'y':
pass
else:
money=0
for i in buy_shop_list:
money_total=(i["price"])
money += money_total
# 當商品購買商品價格總額大于賬戶總額,進行賬戶充值或者直接退出
if money > wages:
print ('您的消費上商品清單%r \n您總共消費 %s 元 ,賬戶余額%s 元 ,余額不足請此卡轉賬或者充值' %(i,money,wages))
money_less=input('請輸入Y/y 登錄新賬戶對此購物車賬號進行轉賬,輸入N/n 不買了: ')
if money_less == Y or money_less == y:
log_other()
else:
if money_less == N or money_less == n:
sys.exit()
else: ? ? ? # 當商品大于價格總額小于賬戶總額購買結束
print ('您購買了%s 物品,\n消費了%s 元' %(buy_shop_list,money))
# 存儲賬戶的消費記錄文件record.txt
with open(r'D:\python_version\python_dir\ATM\log\record.txt','a',encoding='utf-8') as f: ? ? ? # 記錄當天的消費流水
time_t=(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
f.write(time_t)
f.write(' ? ?您消費人民幣 %s 元 \n' %money )
with open(r'D:\python_version\python_dir\ATM\log\balance1.txt', 'w', encoding='utf-8') as k:
# 存儲賬戶余額的文件balance.txt
xiaofei=(wages - money)
money=str(money)
k.write('{\'total_money\':%s,\'shengyu\':%s}'%(wages,xiaofei))
sys.exit()
轉賬模塊:zhuangzhan.py
from?ATM.core.shop?import?buy_shop
import?time,sys,os
def?Transfer():
while?True:
other_id=input('請輸入你其他銀行賬戶信息:')????#?其他銀行賬戶信息
other_pwd=input('請輸入你其他銀行賬戶密碼:')???#其他銀行賬戶密碼
if?other_id?==?'xinyongka'??and??other_pwd?==?'456':
print?('您已經成功登錄,請輸入你要像此admin?賬戶的轉賬金額:')
jine=input('轉賬額:').strip()???????????#登錄后輸入項admin賬戶的轉賬金額
jine=int(jine)???????????????#?轉化為×××(int)
print?('您需要轉賬的金額為?%s?元:?,正在轉賬中....'?%?jine)
time.sleep(3)
with?open(r'D:\python_version\python_dir\ATM\log\balance.txt',?'r+',?encoding='utf-8')?as?file:
file_name?=?eval(file.readline())
syje=(file_name['shengyu'])
syje=int(syje)
new_money=jine+syje?????????????#將轉賬金額與剩余金額相加
print?('您想admin賬戶轉賬?%s?元'?%?jine)
file.write('\n')
file.write('{\'total_money\':%s,\'shengyu\':%s}\n'%(file_name['total_money'],new_money)
sys.exit()