每次做一点就发出来,大神不要嫌重复
2016/11/4
今天来搞ATM,反正逃不了的,说来惭愧,这个作业是我10/4号20天前拿到的,当时是万脸蒙比的,今天又做了一点,现在算是百脸蒙比吧。
一、需求:模拟实现一个ATM + 购物商城程序
额度 15000或自定义
实现购物商城,买东西加入 购物车,调用信用卡接口结账 其实是两套单独程序
可以提现,手续费5% 提现不能超过总余额一半
每月22号出账单,每月10号为还款日,过期未还,按欠款总额 万分之5 每日计息
支持多账户登录,每个用户有单独信息
支持账户间转账,
记录每月日常消费流水
提供还款接口
ATM记录操作日志
提供管理接口,包括添加账户、用户额度,冻结账户等。。。
二、需求分析:
角色:
管理员功能:
增删改查
记录日志
基本信息
额度 15000
普通用户功能:
可以提现,手续费5%
支持多账户登录
支持账户间转账
记录每月日常消费流水
提供还款接口
ATM记录操作日志
三、文件创建
刚开始的蒙比从不知道文件怎么创建开始?擦!怎么多需求,肯定不止一两个文件的,那多个文件又是怎么建的?我还特的心血来潮花一个早上去图去馆研究一下,最后挺乱的,后来看了视频,才发现有文件创建上是有开发规范的!
bin 用于执行可执行文件
conf 配置文件
db 用于存放用户数据
log 日志,记录相关信息
四、begin funny coding
这里我每次写一些,改一些,方便我这种小白看思路,想看最终版的直接拉到文章最后。
16/11/4 9:22
今天实现了检查帐户是否存在,信用卡是否超期的功能。自我感觉良好,哈哈~
学到的新技能:
1. 如何让字体打印出来有颜色??
print("\033[31;1mAccount[%s]doesnotexist!\033[0m" % account)
运行结果:Account [qee] does not exist! 打印出来是红色的
2.如何将一个文件内的字符串形式通过json转化为相应的字典格式??
用json.load()就好嘛,不过还是遇到一点小问题。
#account_file是文件的绝对路径
with open(account_file, "r", encoding="utf-8") as f: #打开文件
file_data = json.load(account_file)
print(file_data)
这样竟然出错了!!
错误信息:AttributeError: 'str' object has no attribute 'read'
于是我去看了下json.load()的源码。
def load(fp, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, **kw): """Deserialize ``fp`` (a ``.read()``-supporting file-like object containing a JSON document) to a Python object. ``object_hook`` is an optional function that will be called with the result of any object literal decode (a ``dict``). The return value of ``object_hook`` will be used instead of the ``dict``. This feature can be used to implement custom decoders (e.g. JSON-RPC class hinting). ``object_pairs_hook`` is an optional function that will be called with the result of any object literal decoded with an ordered list of pairs. The return value of ``object_pairs_hook`` will be used instead of the ``dict``. This feature can be used to implement custom decoders that rely on the order that the key and value pairs are decoded (for example, collections.OrderedDict will remember the order of insertion). If ``object_hook`` is also defined, the ``object_pairs_hook`` takes priority. To use a custom ``JSONDecoder`` subclass, specify it with the ``cls`` kwarg; otherwise ``JSONDecoder`` is used. """ return loads(fp.read(), cls=cls, object_hook=object_hook, parse_float=parse_float, parse_int=parse_int, parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)