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

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

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

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

购物车程序:

  1. ready =
  2. salary = input("how much is you salary:")
  3. out =
  4. #count =
  5. if salary.isdigit():
  6. salary = int(salary)
  7. else:
  8. exit("input string not digital....exit")
  9. list = [["精选猪肉3斤", ], ["牛肉3斤", ], ["鸡肉三斤", ]]
  10. shoppingcar = []
  11. while True:
  12. print("----------------------------------------------------------------------------")
  13. print("Welcome to xiaodai store")
  14. print("\033[31;1m目前正在做活动,购买商品满500的话就赠送一个精美的杯子哦!!!(超市内按h咨询)每人限1次 \033[0m")
  15. for i in enumerate(list):
  16. info_l = i[]
  17. info_n = i[][]
  18. info_m = i[][]
  19. print(info_l, info_n, info_m)
  20. user_c = input("please input your choose(h/help):")
  21. if user_c.isdigit():
  22. user_c = int(user_c)
  23. if user_c < len(list) and user_c >= :
  24. user_c = int(user_c)
  25. money = list[user_c][]
  26. shoppingcar_1 = list[user_c]
  27. ready = ready + money
  28. if salary >= money:
  29. shoppingcar.append(shoppingcar_1)
  30. print(shoppingcar_1, "add in then shoppingcar.....")
  31. salary -= money
  32. else:
  33. print(" ----------------------")
  34. print("|your money not enough:|", salary)
  35. print(" ----------------------")
  36. else:
  37. print("没有这个商品编号")
  38. elif user_c == "h" or user_c == help or user_c == "H":
  39. print("q/quit quit store")
  40. print("c/check check shopping car and salary")
  41. print("0-2 choice of goods")
  42. print("购买完商品后,输入[F]键来参加活动(满500赠送精美杯子)")
  43. print("l/list 查看发票,购买完并退出超市后才能通过此方法看到发票")
  44. elif user_c == "q" or user_c == "quit" or user_c == "Q":
  45. print("your shoppingcar:", shoppingcar)
  46. print("Be left over how much money:", salary)
  47. time_1 = '%Y-%m-%d-%X'
  48. time_2 = time.strftime(time_1)
  49. with open('b.txt', 'a', encoding='utf-8') as f2:
  50. f2.write("发票:%s用户 在 %s 购买了 %s 共消耗%s 元 \n" %(username,time_2,shoppingcar,ready))
  51. exit("quit....")
  52. elif user_c == 'l'or user_c =='list':
  53. with open('b.txt','r+',encoding='utf-8')as f3:
  54. print(f3.read())
  55. elif user_c == "c" or user_c == "check" or user_c == "C":
  56. print("Be left over how much money:", salary)
  57. print(shoppingcar)
  58. elif user_c == "f" or user_c == "F":
  59. if ready >= :
  60. with open('c.txt','r+',encoding='utf-8') as f4:
  61. aready=f4.read()
  62. if username not in aready:
  63. print("你的满额任务达成,获得精美杯子一个..................")
  64. shoppingcar.append(['精美杯子', ])
  65. if len(aready) != :
  66. f4.write('\n'+username)
  67. else:
  68. f4.write(username)
  69. else:
  70. print('你已经领取过奖励了,你的购物车:%s'%shoppingcar)
  71. continue
  72. else:
  73. print("你没有满足活动的需求")
  74. else:
  75. exit("input error")

购物车

所有代码:

  1. import time,sys
  2. def shopping():
  3. "'购物车程序,进入时输入有多少钱,然后进行商品购物,消费满500后选择接受礼品,礼品每个用户只能接受一次,接受过的用户存放在c.txt文件中,购物完毕后打印发票,发票存储在b.txt文件中,"
  4. ready = 0
  5. salary = input("how much is you salary:")
  6. out = 0
  7. #count = 0
  8. if salary.isdigit(): #判断salary是否为数字
  9. salary = int(salary)
  10. else:
  11. exit("input string not digital....exit")
  12. list = [["精选猪肉3斤", 100], ["牛肉3斤", 200], ["鸡肉三斤", 50]]
  13. shoppingcar = []
  14. while True:
  15. print("----------------------------------------------------------------------------")
  16. print("Welcome to xiaodai store")
  17. print("\033[31;1m目前正在做活动,购买商品满500的话就赠送一个精美的杯子哦!!!(超市内按h咨询)每人限1次 \033[0m")
  18. for i in enumerate(list): #enumerate可以在读取数据时添加一个编号在第一位,如[0,"精选猪肉3斤", 100]
  19. info_l = i[0]
  20. info_n = i[1][0]
  21. info_m = i[1][1]
  22. print(info_l, info_n, info_m)
  23. user_c = input("please input your choose(h/help):")
  24. if user_c.isdigit():
  25. user_c = int(user_c)
  26. if user_c < len(list) and user_c >= 0:
  27. user_c = int(user_c)
  28. money = list[user_c][1]
  29. shoppingcar_1 = list[user_c]
  30. ready = ready + money
  31. if salary >= money:
  32. shoppingcar.append(shoppingcar_1)
  33. print(shoppingcar_1, "add in then shoppingcar.....")
  34. salary -= money
  35. else:
  36. print(" ----------------------")
  37. print("|your money not enough:|", salary)
  38. print(" ----------------------")
  39. else:
  40. print("没有这个商品编号")
  41. elif user_c == "h" or user_c == help or user_c == "H":
  42. print("q/quit quit store")
  43. print("c/check check shopping car and salary")
  44. print("0-2 choice of goods")
  45. print("购买完商品后,输入[F]键来参加活动(满500赠送精美杯子)")
  46. print("l/list 查看发票,购买完并退出超市后才能通过此方法看到发票")
  47. elif user_c == "q" or user_c == "quit" or user_c == "Q":
  48. print("your shoppingcar:", shoppingcar)
  49. print("Be left over how much money:", salary)
  50. time_1 = '%Y-%m-%d-%X'
  51. time_2 = time.strftime(time_1)
  52. with open('b.txt', 'a', encoding='utf-8') as f2:
  53. f2.write("发票:%s用户 在 %s 购买了 %s 共消耗%s 元 \n" %(username,time_2,shoppingcar,ready))
  54. exit("quit....")
  55. elif user_c == 'l'or user_c =='list':
  56. with open('b.txt','r+',encoding='utf-8')as f3:
  57. print(f3.read())
  58. elif user_c == "c" or user_c == "check" or user_c == "C":
  59. print("Be left over how much money:", salary)
  60. print(shoppingcar)
  61. elif user_c == "f" or user_c == "F":
  62. if ready >= 500 :
  63. with open('c.txt','r+',encoding='utf-8') as f4:
  64. aready=f4.read()
  65. if username not in aready:
  66. print("你的满额任务达成,获得精美杯子一个..................")
  67. shoppingcar.append(['精美杯子', 0])
  68. if len(aready) != 0 : #len可以打印这个变量中是否有数据,他会显示这个文件的字数,添加这个判断是格式问题,如果文件中没有数据,责直接将数据写入进去,不加空格,如果存在数据,责在插入数据前先执行回车.
  69. f4.write('\n'+username) #在写入内容是在输入回车,不能用逗号来区分,用加号
  70. else:
  71. f4.write(username)
  72. else:
  73. print('你已经领取过奖励了,你的购物车:%s'%shoppingcar)
  74. continue
  75. else:
  76. print("你没有满足活动的需求")
  77. else:
  78. exit("input error")
  79. def auth():
  80. '''慢慢的显示验证中'''
  81. for i in range(1):
  82. sys.stdout.write("验")
  83. sys.stdout.flush()
  84. time.sleep(0.3)
  85. sys.stdout.write("证")
  86. sys.stdout.flush()
  87. time.sleep(0.3)
  88. sys.stdout.write("中")
  89. sys.stdout.flush()
  90. time.sleep(0.3)
  91. sys.stdout.write("请")
  92. sys.stdout.flush()
  93. time.sleep(0.3)
  94. sys.stdout.write("稍")
  95. sys.stdout.flush()
  96. time.sleep(0.3)
  97. sys.stdout.write("等")
  98. sys.stdout.flush()
  99. time.sleep(0.3)
  100. user_list={
  101. 'xiaoming':{'xiaoming1'},
  102. 'xiaogang':{'xiaogang1'},
  103. 'xiaomei':{'xiaomei1'}
  104. }
  105. with open('a.txt','r+',encoding='utf-8')as f:
  106. lock_list=f.read()
  107. count=0
  108. username = input(' please input your user name:')
  109. for l in range(100):
  110. passwd = input('\033[31;3m please input your passwd:\033[1m')
  111. for i in user_list:
  112. auth()
  113. print('\n')
  114. if username in lock_list :
  115. print("用户已被锁定")
  116. break
  117. elif username not in user_list :
  118. print('用户不存在')
  119. username = input(' please input your user name:')
  120. break
  121. else:
  122. a=user_list[username]
  123. if passwd in a :
  124. print('登录成功')
  125. shopping()
  126. elif count >= 3:
  127. print("密码错误次数过多,用户%s被锁定,如需解锁,请联系管理员"%username)
  128. f.write(username)
  129. f.write('\n')
  130. exit('quit...')
  131. else:
  132. print('密码错误登录失败,请重试')
  133. count = count + 1
  134. 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. CSS基础:text-overflow:ellipsis溢出文本显示省略号的详细方法_CSS教程

    4要素: width: 125px;  //宽度必须 text-overflow: ellipsis/clip; //省略号或裁剪: white-space: nowrap;//强制内容在一行显示; ...

  2. php的协程

    有关迭代生成器的内容在这篇博客中 协程 协程的支持是在迭代生成器的基础上, 增加了可以回送数据给生成器的功能(调用者发送数据给被调用的生成器函数). 这就把生成器到调用者的单向通信转变为两者之间的双向 ...

  3. linux命令详解——sed

    sed是一个很好的文件处理工具,本身是一个管道命令,主要是以行为单位进行处理,可以将数据行进行替换.删除.新增.选取等特定工作,下面先了解一下sed的用法 sed命令行格式为:          se ...

  4. LInux基于nginx与OpenSSL实现https访问

    注意!!首先在nginx安装时添加--with-http_ssl_module模块,否则将会报错,只能从头开始了 自建证书: 通过openssl命令(软件包:openssl :openssl-deve ...

  5. bootstap 表格自动换行 截取超长数据

    <table class="table" style="TABLE-LAYOUT:fixed;WORD-WRAP:break_word">

  6. Hadoop_03_Hadoop分布式集群搭建

    一:Hadoop集群简介: Hadoop 集群具体来说包含两个集群:HDFS集群和YARN集群,两者逻辑上分离,但物理上常在一起: HDFS集群:负责海量数据的存储,集群中的角色主要有: NameNo ...

  7. 1.RPC原理学习

    1.什么是RPC:远程过程调用协议 RPC(Remote Procedure Call Protocol)— 远程过程调用协议,是一种通过网络从远程计算机程序上请求服务,而不需要 了解底层网络技术的协 ...

  8. windows 快捷键收集

    1. 放大镜 windows徽标 + "+“ 2. 直接显示桌面 windows徽标 + D 3. 收起所有窗口 windows徽标 + M 4. 浏览器中恢复之前关闭的页面 Ctrl + ...

  9. Almost Regular Bracket Sequence CodeForces - 1095E (线段树,单点更新,区间查询维护括号序列)

    Almost Regular Bracket Sequence CodeForces - 1095E You are given a bracket sequence ss consisting of ...

  10. GIT和SVN的区别(面试)

    Cit是分布式,而SVN不是分布式 存储内容的时候,Git按元数据方式存储,而SVN是按文件 Git没有一个全局版本号,SVN有,目前为止这是SVN相比Git缺少的最大的一个特征 Git的内容完整性要 ...