day2-Cart

#!/usr/bin/env python
#coding:utf-8
#__author__:Bing

import sys,json
import time,datetime

account = {"Gang":{"password" : "test123","lock" : "0","salary":"2000000","cart":{"Tesla Car":"1","House":"1"},"balance":"2000000"},\
           "Yang":{"password" : "test123","lock" : "3","salary":"1000000","cart":{},"balance":"1000000"}
           }
        
marketlist ={"Bikecycle":"200","Tesla Car":"200000","Motocycle":"10000","Apple phone":"5000"}

def preson(name):
    print "This is %s's account information:" % name
    for i in account[name]:
        if "lock" == i or "password" == i:
            pass
        elif "cart" == i:
            #cartlist = ''.join(account[name][i]) 
            print "cart:"
            for j in account[name][i]:
                print " ",j+":"+account[name][i][j]
        else:
            print i+":"+account[name][i]
        
def maket():
    print "\033[5;34;47m*-------------welcome to login system -------------*\033[0m"
    print time.strftime("%Y-%m-%d %a")
    for i in marketlist:
        print i+":"+marketlist[i]


def deal(name):
    preson(name)
    buy = raw_input("What do you need to buy with Yes/No?") 
    if buy.upper() == "YES" or buy.upper() == "yes":
        maket()
        result = raw_input("please input you want to buy:")
        for i in marketlist:
            if str(result) == i:
                balance = int(account[name]["salary"])-int(marketlist[str(result)])
                if balance < 0 :
                    print "Sorry! Notice:Your balance is not enough."
                    break
                else:
                    account[name]["balance"]= str(balance)  #write your balance
                    #count your buy something
                    if str(result) in account[name]["cart"]:
                        account[name]["cart"][str(result)] = str(int(account[name]["cart"][str(result)])+1)
                    else:
                        account[name]["cart"][str(result)] = "1"
    else:
        sys.exit("\033[1;31;47m Thank you for comming! \033[0m")
    
    #product = raw_input("Please input your need buy something:")
while True:
    deal("yang")
本站公眾號
   歡迎關注本站公眾號,獲取更多信息