博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
购物车小程序
阅读量:4697 次
发布时间:2019-06-09

本文共 1657 字,大约阅读时间需要 5 分钟。

第一版:

salary = input('请输入您的总额:') if salary.isdigit():     salary = int(salary) else:     quit('总额仅支持输入数字') list = [] list1=['iphoneX','mac_book','iphone8','python_book'] list2 = [7800,10000,7000,90] msg = ''' ------购物车菜单如下:---------- 0.Iphone X:%d 1.Mac Book:%d 2.Iphone 8:%d 3.Pythone Book:%d 4.退出 ------------------------------ ''' % (list2[0],list2[1],list2[2],list2[3]) print(msg) n=input('>>>>>>>>>>>') if n.isdigit():     n = int(n) else:     quit('仅能输入0-4') while n>-1 and n<4:     if salary-list2[n] < 0:         print('您当前余额不足请及时充值')         break     else:         msg1='''         您当前购买的%s,已加入到购物车。         当前余额为:%d         ''' % (list1[n],salary-list2[n])         print(msg1)         list.append(list1[n]) #把每次购买的商品添加到空数组         salary = salary-list2[n]         n = input('>>>>>>>>>>>>>>')         if n.isdigit():             n=int(n)         else:             print('仅能输入0-4')             break #输出购物车商品 print('您加入购物车的商品如下:') a = len(list) b = 0 while b
product_list = [     ('Mac',9000),     ('kindle',800),     ('tesla',900000),     ('python book',105),     ('bike',2000), ] saving = input('please input your saving:') shopping_car=[] #判断输入saving是否合法 if saving.isdigit():     saving = int(saving)     while True:         #输出商品列表         # for i in product_list:         for i,v in enumerate(product_list,1):             print(i,v[0],v[1])         #     print(product_list.index(i),i[0],':',i[1])         choice=input('选择购买的是那个品编号【退出:q】')         #判断输入的商品序号是否合法         if choice.isdigit():             choice = int(choice)             #判断输入的商品序号是否在数组中             if choice>0 and choice

转载于:https://www.cnblogs.com/xiaobinglife/p/9954809.html

你可能感兴趣的文章
PHP echo 和 print 语句
查看>>
第一讲 一个简单的Qt程序分析
查看>>
Centos 6.5下的OPENJDK卸载和SUN的JDK安装、环境变量配置
查看>>
poj 1979 Red and Black(dfs)
查看>>
【.Net基础03】HttpWebRequest模拟浏览器登陆
查看>>
zTree async 动态参数处理
查看>>
Oracle学习之常见错误整理
查看>>
数据库插入数据乱码问题
查看>>
altium annotate 选项设置 complete existing packages
查看>>
【模式识别与机器学习】——SVM举例
查看>>
【转】IT名企面试:微软笔试题(1)
查看>>
IO流入门-第十章-DataInputStream_DataOutputStream
查看>>
DRF的分页
查看>>
Mysql 模糊匹配(字符串str中是否包含子字符串substr)
查看>>
python:open/文件操作
查看>>
流程控制 Day06
查看>>
Linux下安装Tomcat
查看>>
windows live writer 2012 0x80070643
查看>>
tomcat 和MySQL的安装
查看>>
git常用操作
查看>>