test-信用卡

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
__author__ = 'Administrator'
import sys
import pickle

dict = {123456:['zss','123',15000,15000],234567:['zhaoss','234',15000,15000]}
log_list = {}





shangpin = ['computer','iphone','coffee','notapad']
price = [9000,6000,50,20]

def login():

    n = 0
    while True:
        break_flag = True
        input_name = raw_input("please enter your name:").strip()
        if len(input_name) == 0:continue
        input_pass = raw_input("please enter your password:").strip()
        if len(input_pass) == 0:continue
        global ke
        for ke in dict.iterkeys():
            if input_name == dict[ke][0] and input_pass == dict[ke][1]:
                break_flag = False
                print "hello,%s,welcome!"%(input_name)
                break
            elif input_name == dict[ke][0] and input_pass != dict[ke][1]:
                print u"密码不正确"
                n += 1
                if n >= 3:
                    print u'退出系统'
                    sys.exit()
                continue
            else:
                continue

        if not break_flag:
            break
def shop_list():
    login()
    f_cost = file('account.pkl','rb')
    dict = pickle.load(f_cost)
    print dict
    remain_cost = dict[ke][2]
    while 1:
        print '''========list========='''
        for s in shangpin:
            print shangpin.index(s),s ,price[shangpin.index(s)]

        ch = raw_input(u'请选择(退出选:q)').strip()

        if ch == "q".strip():

            break
        elif ch not in shangpin or len(ch)==0:
            print "please input available shopname"
            continue

        print "so you have select %s"%ch
        remain_cost = remain_cost-price[shangpin.index(ch)]

        dict[ke][2] = remain_cost
        if remain_cost < 0:
            print u'余额不足,买不了这个物品'
            break
        print "he left over money:%d"%(remain_cost)
        pkl_file = file('account.pkl','wb')
        pickle.dump(dict,pkl_file)
        pkl_file.close()


shop_list()
creditcard.py


暂时只有购物功能

后续添加转账 充值 以及日志记录功能

转载于:https://www.cnblogs.com/yangdianfeng007/p/5193931.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值