iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > Python >python 购物流程脚本
  • 567
分享到

python 购物流程脚本

脚本流程python 2023-01-31 05:01:33 567人浏览 八月长安

Python 官方文档:入门教程 => 点击学习

摘要

一、python购物流程脚本半个多月的Python学习,花了一天的时间终于写出来了一个简单的购物流程脚本,也算是对Python的一次总结和知识的温习,本人很菜,脚本也非常非常一般。希望在前辈的基础上能更好的学习Python,希望与大家交流。

一、python购物流程脚本

半个多月的Python学习,花了一天的时间终于写出来了一个简单的购物流程脚本,也算是对Python的一次总结和知识的温习,本人很菜,脚本也非常非常一般。希望在前辈的基础上能更好的学习Python,希望与大家交流。联系方式博客见

此脚本能够实现的实现的功能:
1、通过用户名和密码认证才能登陆购物系统,否者拒绝。
2、认证通过后,用户需要输入工资后会打印一个购物列表,列表中有可以购买的物品。
3、用户可以用自已的工资买购物列表中的物品,前提是自已的工资承受的起,如果承受不起,退出。
4、购买的物品可以加入购物车,也可以从购物车删除。
5、确定购买物品结束后,就可以结算购买物品的总消费金额,然后退出整个系统

此脚本用到python的知识点:
1、流程控制:if | for | while True
2、文件的读取
3、列表的增加和删除
4、模块
5、切片
6、索引
......
#!/usr/bin/env python
# Descript message
# Author:Allentuns
# MailBox:zhengyansheng@hytyi.com
# Tel:13260071987

import startup
import sys

userfile = open("user.txt","r")
rss = userfile.readlines()
listpass = []

for line in rss:
        line1 = line.split()[0]
        listpass.append(line1)

username1 = listpass[0::2]
passWord1 = listpass[1::2]


while True:
        user = raw_input("please input your username:")

        user_num = username1.index(user)
        user_pas = password1[user_num]

        if len(user) == 0:
                print "empty user,try again."
                continue
        elif user in username1:
                break
        elif user == "q" or user == "quit" or user == "exit":
                print "Welcome to come again next time"
                sys.exit()
        else:
                print "%s is not exists,please try again input your name" %(user)
                continue

while True:
        passwdd = raw_input("please your password:")
        if len(passwdd) == 0:
                print "Sorry , input your password error , please try again."
        #elif passwdd in password1:
        elif passwdd == user_pas:
                print "\n" + "Welcome to %s login shoppings:" %(user)
                break
        else:
                print "password is Error,please try again."


while True:
        try:
                salary = int(raw_input("please input your salary:"))
                break
        except ValueError:
                print "please input a number,not string."


file = open('shoplist.txt','r')
for fr in file:
        fr = fr.rstrip()
        print fr
file.close()


print """Options and arguments:
         input "D" : Delete from shoplist into del
         input "F" : Return to the total pages
         input "T" : Total shoplist"""

products = []
prices   = []

file2 = open('shoplist.txt')
fr2 = file2.readlines()

for line in fr2:
        p1 = line.split()[0]
        p2 = int(line.split()[1])
        products.append(p1)
        prices.append(p2)
        prices = prices


list00 = []
while True:
        choose = raw_input("please choose your buy things:")
        if choose in products:
                product_num = products.index(choose)
                product_price = prices[product_num]
                if salary > product_price:
                        print "%s $%d" %(choose,product_price)
                        list00.append(choose)
                        print "Add %s into your shoplist" %(choose)
                        print "You choose to purchase the commodity list:",list00
                        salary = salary - product_price
                else:
                        if salary < min(prices):
                                print "Sorry , reset of your salary cannot buy anythings."
                                sys.exit()
        elif choose == "T":
                print "salary left :$%s" %(salary)
                print "You choose to purchase the commodity list:",list00
                sys.exit()
        elif choose == "D":
                while True:
                        delchoose = raw_input("your will things remove from into shoplist:")
                        if delchoose in products:
                                product_num2 = products.index(delchoose)
                                product_price2 = prices[product_num2]
                                salary = salary + product_price2
                                list00.remove(delchoose)
                                print list00
                                print salary
                                break


二、脚本测试

[root@python 20141105]# python list.py
please input your username:allentuns    #输入错误的用户名,则登陆失败
allentuns is not exists,please try again input your name
please input your username:ad
ad is not exists,please try again input your name
please input your username:admin    #输入正确的用户名后,可以继续输入密码
please your password:000            #密码输入错误后,尝试继续在次输入
password is Error,please try again.    
please your password:a
password is Error,please try again.
please your password:000000        #密码输入正确后,可以继续下一步操作

Welcome to admin login shoppings:
please input your salary:20000    #输入工资,打印购物列表
Apple	13500
Iphone 	4500
Bike	490
Samsung	2900
Piano	1600
Coffer	35
Options and arguments:
         input "D" : Delete from shoplist into del
         input "F" : Return to the total pages
         input "T" : Total shoplist
please choose your buy things:Apple    #选择想要购买的物品1,并加入到购物车
Apple $13500
Add Apple into your shoplist
You choose to purchase the commodity list: ['Apple']    #已经成功加入到购物车
please choose your buy things:Bike     #选择想要购买的物品2,并加入到购物车
Bike $490
Add Bike into your shoplist
You choose to purchase the commodity list: ['Apple', 'Bike']    #已经成功加入到购物车
please choose your buy things:Coffer    #选择想要购买的物品3,并加入到购物车
Coffer $35
Add Coffer into your shoplist
You choose to purchase the commodity list: ['Apple', 'Bike', 'Coffer']
please choose your buy things:D    #如果此时感觉不想买Bike了,可以从购物车将其删除
your will things remove from into shoplist:Bike    #删除购物车的物品
['Apple', 'Coffer']
6465
please choose your buy things:T    #要购买的物品已经购买完毕,此时可以结账,退出系统
salary left :$6465
You choose to purchase the commodity list: ['Apple', 'Coffer']    #打印购买的物品

三、登陆认证用户文件和购物列表文件

[root@python 20141105]# cat user.txt     #认证用户和密码列表
jerry
123456
Kimits
873902
admin
000000
[root@python 20141105]# cat shoplist.txt  #购物列表单
Apple	13500
Iphone 	4500
Bike	490
Samsung	2900
Piano	1600
Coffer	35

--结束END--

本文标题: python 购物流程脚本

本文链接: https://www.lsjlt.com/news/188750.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • python 购物流程脚本
    一、Python购物流程脚本半个多月的python学习,花了一天的时间终于写出来了一个简单的购物流程脚本,也算是对Python的一次总结和知识的温习,本人很菜,脚本也非常非常一般。希望在前辈的基础上能更好的学习Python,希望与大家交流。...
    99+
    2023-01-31
    脚本 流程 python
  • 怎么用python脚本实现购物车小程序
    这篇“怎么用python脚本实现购物车小程序”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“怎么用python脚本实现购物车小...
    99+
    2023-06-29
  • Python制作脚本帮女朋友抢购清空购物车
    目录爬取目标工具使用需求分析项目思路解析selenium安装配置项目解析简易源码分享大家好,我是辣条。 辣条的一个朋友最近跟我诉苦:女朋友沉迷淘宝抢购无法自拔,大晚上不睡觉都在定时...
    99+
    2024-04-02
  • 【Python】京东自动下单抢购脚本——双十一购物小技巧
    最近种草一款富士📷已久,但限于富士产能,一直都没有等到开放购买,在尝试几次定闹钟到点准时抢购后,果断放弃,于是花了一个周末时间写了一个简易脚本,终于成为一名合格的“富家子弟”。 ...
    99+
    2023-09-03
    python java 抢购 抢购脚本 京东
  • python 购物车程序
    需求:1.启动程序后,让用户输入工资,然后打印商品列表2.允许用户根据商品编号购买商品3.用户选择商品后,检测余额是否够,够就直接扣款,不够就提醒 4.可随时退出,退出时,打印已购买商品和余额首先分析第1条,输入工资,只需要执行一...
    99+
    2023-01-30
    购物车 程序 python
  • python淘宝抢购脚本程序实现
    目录一、官网下载火狐浏览器二、下载geckodriver,并解压到火狐浏览器文件夹根目录三、添加火狐浏览器根目录到系统环境变量四、下载并安装python3及pycharm开发工具&n...
    99+
    2024-04-02
  • python之购物车程序
    题目: 购物车程序业需求:数据结构:goods = [{"name": "电脑", "price": 1999},{"name": "鼠标", "price": 10},{"name": "游艇", "price": 20},{"name"...
    99+
    2023-01-31
    购物车 程序 python
  • python 的 购物小程序
    1 money = input('请输入您的工资:') 2 shop = [("iphone",5800),("ipod",3000),("book",210),("Archer python",80)] 3 while no...
    99+
    2023-01-30
    程序 python
  • Python学习:购物程序
    一.脚本要求启动程序后,让用户输入工资,然后打印商品列表;允许用户根据商品的编号购买商品;用户选择商品后,检测余额是否够,够就直接扣款,不够就提醒;结算购物车,打印已购买商品和余额;可随时退出程序;二.涉及Python知识点注释变量用户输入...
    99+
    2023-01-31
    程序 Python
  • Python如何实现抢购脚本
    这篇文章将为大家详细讲解有关Python如何实现抢购脚本,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。Python脚本实现安装Python。我安装的是anaconda安装webdriver扩展。它是Sel...
    99+
    2023-06-25
  • Jmeter并发执行Python 脚本的完整流程
    目录1. 前言2. Python 实现文件上传2-1获取文件信息及切片数目2-2切片及分段上传2-3合并文件2-4文件路径参数化3. Jmeter 并发执行4. 最后本篇文章以文件上...
    99+
    2024-04-02
  • Python实现自动填写脚本流程详解
    目录前言环境使用模块使用本次案例代码实现思路最终效果代码实现前言 环境使用 Python 3.8Pycharm 模块使用 import requests —> 数据...
    99+
    2024-04-02
  • 用python写一个抢购的脚本
    好的,这是用 Python 写的一个抢购的脚本的示例: import requestsdef main(): # 在这里输入你的抢购商品的 URL url = "http://www.example.com/product/123" ...
    99+
    2023-10-05
    java 开发语言
  • Python抢购脚本的编写方法
    想买mate40,但总是抢不到,所以想试着能不能写个脚本代码。 第一步:把想要抢购的商品加进购物车,注意:脚本是对购物车内全部商品进行下单操作,所以不够买的商品最好先从购物车内删除。...
    99+
    2024-04-02
  • python实现购物车小程序
    本文实例为大家分享了python实现购物车小程序的具体代码,供大家参考,具体内容如下 功能实现: (1)可以查看购物车的商品,和余额 (2)可以显示商品列表,根据商品的编号选择商品 ...
    99+
    2024-04-02
  • python编写购物车小程序
     #练习#程序购物车#启动程序后,让用户输入工资,  然后打印商品列表,允许用户根据商品编号购买商品用户选择商品后 #检测余额是否够,够就直接扣款,不够就提醒可随时退出,退出时,打印已购买商品和余额  commdity_dict={ ...
    99+
    2023-01-30
    购物车 程序 python
  • [python] 转换python脚本程
    方法1: freeze.py 来自python源码树. 安装pythonbrew,可安装定制化的独立python环境(略) python trunk/Tools/freeze/freeze.py ./pkgdep.py 之后make即可...
    99+
    2023-01-31
    脚本 python
  • 简化购物之旅:CMS购物车功能的便利与流畅
    在当今电子商务时代,购物方式日新月异,CMS购物车功能的出现,为消费者和企业带来了全新的购物体验。CMS购物车功能,使购物过程变得更加便捷和流畅,从而大大提升了客户满意度和企业的销售业绩。 1. 用户友好界面,简化购物之旅 CMS购物车...
    99+
    2024-02-23
    CMS 购物车 功能 便捷 流畅 用户体验 消费者 企业
  • Python购物车练习
    要求:    1.启动程序后,然该用户输入工资,然后打印商品列表    2.允许用户根据商品编号购买商品    3.用户选择商品后,检测余额是否足够,够就直接扣款,不够就提醒    4.可随时退出,退出时,打印已购买商品和余额python代...
    99+
    2023-01-31
    购物车 Python
  • python-ATM加购物车
    模拟实现一个ATM + 购物商城程序 1.额度 15000或自定义 4.支持多账户登录 ...
    99+
    2023-01-30
    购物车 python ATM
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作