用python写atm自动取款_Python实现atm机的功能

本文介绍了一个使用Python编写的ATM机模拟程序,具备购物、查询余额、存款、取款、转账、查看账单及修改密码等功能。程序通过pickle模块进行数据持久化,允许用户进行日常消费流水记录,并在每月最后一天自动生成账单。同时,程序还提供了商品购物功能,用户可以在预设的商品列表中选择购买商品。
摘要由CSDN通过智能技术生成

主要还是参考网上内容,自己做了修改。虽然代码有小bug,但是不影响学习和测试。

功能:

1.额度:8000

2.可以提现,手续费5%

3.每月最后一天出账单,写入文件

4.记录每月日常消费流水

5.提供还款接口

1.atm的脚本[root@python atm]# cat atm.py

#!/usr/bin/env python

# -*- coding: utf-8 -*-

'''

Date:2017-03-23

Author:Bob

'''

import os

import time

import pickle

import readline #解决退格键和上下键引起的乱码,需要安装readline和readline-devel包

#定义账单,商品和购物车

Bill = {}

products = {}

shoplist = []

#define Bill function, used to record billing details(account/time/describe/money).

def Bill(Account,Time,Description,RMB):

Bill = {"Account":Account,"Time":Time,"Description":Description,"RMB":RMB}

#用pickle模块把账单信息存入到bill文件中去

pickle.dump(Bill,open("bill","a"))

#购物功能

def shop():

print '\033[;32mWelcome to shopping!\n\033[0m'

with open('shops.txt') as f:

for line in f.readlines():

print '{}'.format(line.strip())

while 1:

with open('shops.txt') as f:

for line in f.readlines():

line = line.strip()

commodity = line.split()[0]

price = line.split()[1]

products[commodity] = price

choice = raw_input("\n\033[;36mPlease enter what you want to buy,if you want back,you can enter\033[0m \033[;31mback\033[0m:").strip()

if len(choice) == 0:

continue

elif choice == 'back':

list()

#如果有这个商品,就判断商品价格,如果商品价格大于余额,就提示余额不足

if products.has_key(choice):

#从userinfo文件中读取并反序列化

remaining = pickle.load(open('userinfo','rb'))

if int(products[choice]) > remaining[accountAuth][2]:

print 'In your card remaining sum already insufficiency, please prompt sufficient value!'

else:

while 1:

#把购买的商品追加到购物车

shoplist.append(choice)

#计算余额,余额就是总金额减去购买的商品价格

new_remaining = int(remaining[accountAuth][2]) - int(products[choice])

userInfo[accountAuth][2] = int(new_remaining)

#把余额信息序列化并存到userinfo文件中

pickle.dump(userInfo,open("userinfo","wb"))

#把购买的记录和账单写到Bill文件中

Bill(accountAuth,time.strftime("%Y-%m-%d %H:%M:%S"),choice,"-%d" % int(products[choice]))

#打印消费的金额和剩余金额

print "\033[;32mConsumption is %r Money is %r\033[0m" % (products[choice],new_remaining)

#打印购物车的商品

print "\033[;33mThe shopping list %s \033[0m" % shoplist

break

else:

print 'You choose {} is not in the shoplist!'.format(choice)

shop()

#查询余额功能

def query_money():

userInfo = pickle.load(open('userin

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值