购物订单系统:
#!usr/bin/env python # encoding: utf-8 import sys i = 0 inventory_dic = {'Car':1000,'SUV':5000,'Mac':300,'iPhone':1500,'Pen':10} account_dic = {'wyh':123,'cloudsea':456} balance = {'wyh':10000,'cloudsea':5000} detail_list = [] #把锁定的用户读取到空列表中 l = [] f = open('lock.txt','r') for n in f.readlines(): s = n.strip(' ') l.append(s) f.close() #验证用户名和密码 def verification(aot,pw): if aot not in account_dic.keys(): print('你的账户名错误!') return 0 elif pw != account_dic[aot]: print('你的密码错误!') return 0 else: print('欢迎进入购物菜单!') return 1 while True: aot = input('请输入你的账户:').strip() pw = int(input('请输入密码:')) if aot in l: print('你的账号被锁定,请联系你的管理员解锁!') sys.exit() if verification(aot,pw) == 0: i += 1 if i == 3: print('锁定账号,请联系你的管理员!') with open('lock.txt','a') as p: p.write(aot +' ') sys.exit() continue else: print('你的账户余额:%s'% balance[aot]) break #进入购物系统 while True: for k,v in inventory_dic.items(): print('%s:%s'%(k,v)) Num = input('请选择你要购买的商品名称(退出:q):') if Num == 'q': print(detail_list) print('你的余额:%s' % balance[aot]) sys.exit() elif balance[aot] < min(inventory_dic.values()): print('你的余额太少,请充值后在进行购买!') sys.exit() elif balance[aot] < inventory_dic[Num]: print('你的余额%s:你买不起,请从新选择'%balance[aot]) continue elif Num in inventory_dic.keys(): detail_list.append(Num) balance[aot] = balance[aot] - inventory_dic[Num] print('你的余额:%s' % balance[aot]) continue else: print('你选择的商品不在清单中,请从新选择。') continue