python实现购物网站(Python实战购物车项目的实现参考)
类别:脚本大全 浏览量:1723
时间:2022-01-26 01:08:57 python实现购物网站
Python实战购物车项目的实现参考购物车程序
要求如下图
代码
|
# --*--coding:utf-8--*-- # author: 村雨 import pprint productlist = [( 'iphone 8' , 10000 ), ( 'gtx2080' , 8000 ), ( 'z7kp7-gt' , 6000 ), ( 'mac pro' , 15000 ), ( 'honor 10' , 2800 ), ( 'iphone xr' , 12000 ), ( 'mi 8' , 2999 ) ] shoppinglist = [] print ( '输入你的工资:' ) salary = input () if not salary.isdigit(): print ( '请输入整数' ) else : salary = int (salary) while true: for index, item in enumerate (productlist): print (index + 1 , item) print ( '输入你要买的商品的序号:' ) userwant = input () if userwant.isdigit(): userwant = int (userwant) if userwant < = len (productlist) and userwant > 0 : print ( '你要购买的是:' , productlist[userwant - 1 ][ 0 ]) if salary > = productlist[userwant - 1 ][ 1 ]: shoppinglist.append(productlist[userwant - 1 ][ 0 ]) salary - = productlist[userwant - 1 ][ 1 ] print ( '你已经购买了' + productlist[userwant - 1 ][ 0 ] + ', 你的余额为 ' + str (salary)) else : print ( '对不起,你的余额不足!请努力工作吧!' ) print ( '你当前所购买的商品为:' ) for brought in shoppinglist: pprint.pprint(brought) print ( '你当前余额为:' , salary) exit() else : print ( '你输入的商品序号有错,请重新输入' ) elif userwant = = 'q' : print ( '-----------shopping list----------' ) for brought in shoppinglist: pprint.pprint(brought) print ( '你的余额为 ' , salary) exit() else : print ( 'invalid input!!!' ) |
结果
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对开心学习网的支持。如果你想了解更多相关内容请查看下面相关链接
原文链接:https://blog.csdn.net/github_39655029/article/details/82747768
您可能感兴趣
- python怎么在csv修改数据(python 编写输出到csv的操作)
- python复杂的验证码处理(Python 通过打码平台实现验证码的实现)
- python获取excelsheet名称(python查询文件夹下excel的sheet名代码实例)
- python怎么进行参数传递(在Python中如何传递任意数量的实参的示例代码)
- python scrapy 框架原理(一步步教你用python的scrapy编写一个爬虫)
- pythonmatplotlib绘制立体图形(python3使用matplotlib绘制散点图)
- python 验证码识别模块([机器视觉]使用python自动识别验证码详解)
- python数组矩阵操作(Python矩阵和Numpy数组的那些事儿)
- python操作redis(Python获取Redis所有Key以及内容的方法)
- python弹球游戏编写过程(python实现坦克大战游戏 附详细注释)
- python中对象方法和顶级方法(Python3.5面向对象程序设计之类的继承和多态详解)
- python3 代码解读(Python3列表内置方法大全及示例代码小结)
- python中字符串常用函数或方法(Python3.5字符串常用操作实例详解)
- python发送微信消息脚本(python实现给微信指定好友定时发送消息)
- python统计图参数(Python使用统计函数绘制简单图形实例代码)
- python怎么爬取excel数据(python爬取内容存入Excel实例)
- 重庆旅游攻略(重庆旅游3-4天攻略最佳线路)
- 周杰伦演唱会门票(周杰伦演唱会门票多少钱一张2023)
- 焕然一新 成都轨道集团官方网站改版上线(成都轨道集团官方网站改版上线)
- 成都轨道交通19号线二期全线电通(成都轨道交通19号线二期全线电通)
- 19号线二期全线电通 轨道交通项目最新进展来了(19号线二期全线电通)
- 涉及3条地铁线路 成都这4座轨道交通站点有新名字了(涉及3条地铁线路)
热门推荐
- ftp服务器两种连接方式(FTP服务器 架设考虑三方面的安全因素)
- dedecms怎么添加alt标签(dedecms 取消栏目列表页文章标题设置推荐后的加粗)
- 云服务器必须购买吗(购买真正的云服务器,这几个方面要小心)
- ubuntu安装php(在Ubuntu 18.04上安装PHP 7.3 7.2和7.0的方法)
- python爬取豆瓣评分排行榜(Python爬虫——爬取豆瓣电影Top250代码实例)
- html5如何控制内容(html5拖拽应用记录及注意点)
- SQLServer中防止并发插入重复数据的方法详解(SQLServer中防止并发插入重复数据的方法详解)
- 反射中BindingFlags的值
- python里range循环(Python for循环与range函数的使用详解)
- python中怎么输入单引号(python三引号输出方法)
排行榜
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9