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


暂时只有购物功能

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

posted @ 2016-02-16 22:00  杨点风007  阅读(178)  评论(0编辑  收藏  举报