创建文件a.txt,b.txt.c.txt用于存放应该持续保存的信息

a.txt :用户密码输入错误3次就锁定

b.txt :购物时的活动,每个用户只能参与一次

c:txt :购物完后的发票在这里查看

购物车程序:

  ready =
salary = input("how much is you salary:")
out =
#count =
if salary.isdigit():
salary = int(salary)
else:
exit("input string not digital....exit")
list = [["精选猪肉3斤", ], ["牛肉3斤", ], ["鸡肉三斤", ]]
shoppingcar = []
while True:
print("----------------------------------------------------------------------------")
print("Welcome to xiaodai store")
print("\033[31;1m目前正在做活动,购买商品满500的话就赠送一个精美的杯子哦!!!(超市内按h咨询)每人限1次 \033[0m")
for i in enumerate(list):
info_l = i[]
info_n = i[][]
info_m = i[][]
print(info_l, info_n, info_m)
user_c = input("please input your choose(h/help):")
if user_c.isdigit():
user_c = int(user_c)
if user_c < len(list) and user_c >= :
user_c = int(user_c)
money = list[user_c][]
shoppingcar_1 = list[user_c]
ready = ready + money
if salary >= money:
shoppingcar.append(shoppingcar_1)
print(shoppingcar_1, "add in then shoppingcar.....")
salary -= money
else:
print(" ----------------------")
print("|your money not enough:|", salary)
print(" ----------------------")
else:
print("没有这个商品编号")
elif user_c == "h" or user_c == help or user_c == "H":
print("q/quit quit store")
print("c/check check shopping car and salary")
print("0-2 choice of goods")
print("购买完商品后,输入[F]键来参加活动(满500赠送精美杯子)")
print("l/list 查看发票,购买完并退出超市后才能通过此方法看到发票")
elif user_c == "q" or user_c == "quit" or user_c == "Q":
print("your shoppingcar:", shoppingcar)
print("Be left over how much money:", salary)
time_1 = '%Y-%m-%d-%X'
time_2 = time.strftime(time_1)
with open('b.txt', 'a', encoding='utf-8') as f2:
f2.write("发票:%s用户 在 %s 购买了 %s 共消耗%s 元 \n" %(username,time_2,shoppingcar,ready))
exit("quit....")
elif user_c == 'l'or user_c =='list':
with open('b.txt','r+',encoding='utf-8')as f3:
print(f3.read())
elif user_c == "c" or user_c == "check" or user_c == "C":
print("Be left over how much money:", salary)
print(shoppingcar)
elif user_c == "f" or user_c == "F":
if ready >= :
with open('c.txt','r+',encoding='utf-8') as f4:
aready=f4.read()
if username not in aready:
print("你的满额任务达成,获得精美杯子一个..................")
shoppingcar.append(['精美杯子', ])
if len(aready) != :
f4.write('\n'+username)
else:
f4.write(username)
else:
print('你已经领取过奖励了,你的购物车:%s'%shoppingcar)
continue
else:
print("你没有满足活动的需求")
else:
exit("input error")

购物车

所有代码:

import time,sys
def shopping():
"'购物车程序,进入时输入有多少钱,然后进行商品购物,消费满500后选择接受礼品,礼品每个用户只能接受一次,接受过的用户存放在c.txt文件中,购物完毕后打印发票,发票存储在b.txt文件中,"
ready = 0
salary = input("how much is you salary:")
out = 0
#count = 0
if salary.isdigit(): #判断salary是否为数字
salary = int(salary)
else:
exit("input string not digital....exit")
list = [["精选猪肉3斤", 100], ["牛肉3斤", 200], ["鸡肉三斤", 50]]
shoppingcar = []
while True:
print("----------------------------------------------------------------------------")
print("Welcome to xiaodai store")
print("\033[31;1m目前正在做活动,购买商品满500的话就赠送一个精美的杯子哦!!!(超市内按h咨询)每人限1次 \033[0m")
for i in enumerate(list): #enumerate可以在读取数据时添加一个编号在第一位,如[0,"精选猪肉3斤", 100]
info_l = i[0]
info_n = i[1][0]
info_m = i[1][1]
print(info_l, info_n, info_m)
user_c = input("please input your choose(h/help):")
if user_c.isdigit():
user_c = int(user_c)
if user_c < len(list) and user_c >= 0:
user_c = int(user_c)
money = list[user_c][1]
shoppingcar_1 = list[user_c]
ready = ready + money
if salary >= money:
shoppingcar.append(shoppingcar_1)
print(shoppingcar_1, "add in then shoppingcar.....")
salary -= money
else:
print(" ----------------------")
print("|your money not enough:|", salary)
print(" ----------------------")
else:
print("没有这个商品编号")
elif user_c == "h" or user_c == help or user_c == "H":
print("q/quit quit store")
print("c/check check shopping car and salary")
print("0-2 choice of goods")
print("购买完商品后,输入[F]键来参加活动(满500赠送精美杯子)")
print("l/list 查看发票,购买完并退出超市后才能通过此方法看到发票")
elif user_c == "q" or user_c == "quit" or user_c == "Q":
print("your shoppingcar:", shoppingcar)
print("Be left over how much money:", salary)
time_1 = '%Y-%m-%d-%X'
time_2 = time.strftime(time_1)
with open('b.txt', 'a', encoding='utf-8') as f2:
f2.write("发票:%s用户 在 %s 购买了 %s 共消耗%s 元 \n" %(username,time_2,shoppingcar,ready))
exit("quit....")
elif user_c == 'l'or user_c =='list':
with open('b.txt','r+',encoding='utf-8')as f3:
print(f3.read())
elif user_c == "c" or user_c == "check" or user_c == "C":
print("Be left over how much money:", salary)
print(shoppingcar)
elif user_c == "f" or user_c == "F":
if ready >= 500 :
with open('c.txt','r+',encoding='utf-8') as f4:
aready=f4.read()
if username not in aready:
print("你的满额任务达成,获得精美杯子一个..................")
shoppingcar.append(['精美杯子', 0])
if len(aready) != 0 : #len可以打印这个变量中是否有数据,他会显示这个文件的字数,添加这个判断是格式问题,如果文件中没有数据,责直接将数据写入进去,不加空格,如果存在数据,责在插入数据前先执行回车.
f4.write('\n'+username) #在写入内容是在输入回车,不能用逗号来区分,用加号
else:
f4.write(username)
else:
print('你已经领取过奖励了,你的购物车:%s'%shoppingcar)
continue
else:
print("你没有满足活动的需求")
else:
exit("input error")
def auth():
'''慢慢的显示验证中'''
for i in range(1):
sys.stdout.write("验")
sys.stdout.flush()
time.sleep(0.3)
sys.stdout.write("证")
sys.stdout.flush()
time.sleep(0.3)
sys.stdout.write("中")
sys.stdout.flush()
time.sleep(0.3)
sys.stdout.write("请")
sys.stdout.flush()
time.sleep(0.3)
sys.stdout.write("稍")
sys.stdout.flush()
time.sleep(0.3)
sys.stdout.write("等")
sys.stdout.flush()
time.sleep(0.3)
user_list={
'xiaoming':{'xiaoming1'},
'xiaogang':{'xiaogang1'},
'xiaomei':{'xiaomei1'}
}
with open('a.txt','r+',encoding='utf-8')as f:
lock_list=f.read()
count=0
username = input(' please input your user name:')
for l in range(100):
passwd = input('\033[31;3m please input your passwd:\033[1m')
for i in user_list:
auth()
print('\n')
if username in lock_list :
print("用户已被锁定")
break
elif username not in user_list :
print('用户不存在')
username = input(' please input your user name:')
break
else:
a=user_list[username]
if passwd in a :
print('登录成功')
shopping()
elif count >= 3:
print("密码错误次数过多,用户%s被锁定,如需解锁,请联系管理员"%username)
f.write(username)
f.write('\n')
exit('quit...')
else:
print('密码错误登录失败,请重试')
count = count + 1
break #为了确保如"密码错误登录失败,请重试"提示只提示一次,而不是按照for循环的提示多次,当执行完后就退出for循环,退出后又继续加载这个循环。

  

python 购物车+用户认证程序的更多相关文章

  1. Python的用户交互程序及格式化输出

    1.  用户输入 在Python 3 中,用户输入用input()函数即可实现用户交互程序. 例如,我们根据程序提示输入用户名和密码,并且打印输入的信息. 2. 字符串格式化输出 例如,我们根据程序提 ...

  2. Python入门-用户登录程序升级版

    编写登陆接口 基础需求: 让用户输入用户名密码 认证成功后显示欢迎信息 输错三次后退出程序 升级需求: 可以支持多个用户登录 (提示,通过列表存多个账户信息) 用户3次认证失败后,退出程序,再次启动程 ...

  3. Python入门-用户登录程序

    _flag = Falsecount = 0users = [['ziv', '123'], ['alex', '12345']]while count < 3: username = inpu ...

  4. 用户认证授权和Shiro入门

    1.权限管理基础(认证和授权): 前言 本文主要讲解的知识点有以下: 权限管理的基础知识 模型 粗粒度和细粒度的概念 回顾URL拦截的实现 Shiro的介绍与简单入门 一.Shiro基础知识 在学习S ...

  5. python 全栈开发,Day104(DRF用户认证,结算中心,django-redis)

    考试第二部分:MySQL数据库 6.  MySQL中char和varchar的区别(1分) char是定长,varchar是变长. char的查询速度比varchar要快. 7.   MySQL中va ...

  6. python 购物车小程序

    python 购物车小程序 功能要求:1.启动程序后,输入用户名密码后,让用户输入工资,然后打印商品列表2.允许用户根据商品编号购买商品3.用户选择商品后,检测余额是否够,够就直接扣款,不够就提醒4. ...

  7. python 全栈开发,Day79(Django的用户认证组件,分页器)

    一.Django的用户认证组件 用户认证 auth模块 在进行用户登陆验证的时候,如果是自己写代码,就必须要先查询数据库,看用户输入的用户名是否存在于数据库中: 如果用户存在于数据库中,然后再验证用户 ...

  8. Python学习笔记一:第一个Python程序,变量,字符编码与二进制,用户交互程序

    第一个python程序 Windows:设置环境变量,X:\pthonxxx,xxx是版本号 在命令提示符下 输入python,进入解释器 >>>print(“Hello World ...

  9. redis介绍及在购物车项目中的应用,用户认证

    1.redis 2.购物车的构建 api结构: models.py(创建完后自行添加数据) from django.db import models from django.contrib.conte ...

随机推荐

  1. a标签 href不跳转 禁止跳转

    当页面中a标签不需要任何跳转时,从原理上来讲,可分如下两种方法: 标签属性href,使其指向空或不返回任何内容.如: <a href="javascript:void(0);" ...

  2. 笔记 前端的$dom操作

    jqueryDOM操作  1.  页面加载  函数 $( function(){ 具体内容 } );        表示页面加载函数   2  dom 类操作 text() - 设置或返回所选元素的文 ...

  3. 二、CentOS 7安装部署GitLab服务器(解决邮箱发信问题)

    一.环境安装(10.0.0) 1.安装依赖软件 yum -y install policycoreutils policycoreutils-python openssh-server openssh ...

  4. Linux工具之ss

    1.SS命令 (Socket   Statistics),获取socket统计信息,显示和netstat类似的内容.显示更详细的TCP连接信息.   命令功能: ss(Socket Statistic ...

  5. CSS基础学习-12.CSS position

    绝对定位 position:absolute,元素脱离文档流,然后使用left.right.top.bottom属性相对于其最接近的一个具有定位属性的祖先元素进行绝对定位.如果不存在这样的祖先元素,则 ...

  6. Kafka、RabbitMQ、RocketMQ等 消息中间件 介绍和对比

    文章目录 1.前言 2.概念 2.1.MQ简介 2.2.MQ特点 2.2.1.先进先出 2.2.2.发布订阅 2.2.3.持久化 2.2.4.分布式 3.消息中间件性能究竟哪家强? 3.1.Kafka ...

  7. 我遇到的Echarts 最大值不显示&平均值不正常

    用Echarts做图表的时候,遇到最大值不显示和平均值不正常的问题,如图: 找了半天,原来是X轴6个坐标有7个数据,只是最后那个数据没有显示出来,而且还是最大的,无语. 加上第七个坐标之后,就显示正常 ...

  8. 原来你是这样的 jsonp(原理与具体实现细节)

    前言 原文地址 仓库地址 jsonp(JSON with padding)你一定不会陌生,前端向后端拿数据的方式之一,也是处理跨域请求的得利助手. 我们早已习惯,早已熟练了jQ或者zepto的ajax ...

  9. ssh远程连接centos7故障排除

    导致故障的原因在两个方面 1.网络问题---物理链路就不通可以通过在客户端 telnet目标主机地址,例如:telnet 192.168.1.107 22 千万别忘了端口号!!!,如果通了还连不上则按 ...

  10. java 日期增加

    import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public cl ...