#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @File : 20180510001.py
# @Author: Anthony.waa
# @Date : 2018/5/10 0007
# @Desc : # 购物清单列表
goods = [
{"name": "书籍", "price": 1999},
{"name": "服装", "price": 10},
{"name": "美女", "price": 20},
{"name": "科技用品", "price": 998},
] # 定义空购物车
shopping = [] # 显示购物清单
print("---欢迎登陆购物系统")
for goods_count, goods_all in enumerate(goods,1):
print(goods_count, goods_all['name'], goods_all['price']) # 循环购物流程
while True: # 输入总金额
salary = input("请输入你当前总资产:").strip()
if salary.isdigit():
salary = int(salary)
else:
print("输入错误,请重新输入.")
continue while True:
# 选择购物商品,并加入购物清单
choice = input("请选择你要购物的商品:").strip()
goods_index = len(goods) if choice.isdigit():
choice = int(choice) # 判断输入选项不能小于元素长度
if choice > 0 and choice <= goods_index:
name_a = goods[choice - 1]['name'] # 单个商品名称
price_a = goods[choice - 1]['price'] # 单个商品价格
if salary > price_a:
if choice == 1:
shopping.append(name_a)
print('购买成功,当前购物车内有:', shopping, '剩余金额为:', salary)
elif choice == 2:
shopping.append(name_a)
print('购买成功当前购物车内有:', shopping, '剩余金额为:', salary)
elif choice == 3:
shopping.append(name_a)
print('购买成功当前购物车内有:', shopping, '剩余金额为:', salary)
elif choice == 4:
shopping.append(name_a)
print('购买成功当前购物车内有:', shopping, '剩余金额为:', salary)
else:
print('没有该类目,请重新输入') salary -= price_a # 剩余金额 else:
print("余额不足,请充值。")
# 充值金额
salary_two = int(input("请输入充值金额:"))
salary += salary_two
print("余额为:", salary)
continue
elif choice.lower():
if choice == 'q':
print("欢迎下次再来,再见。")
exit()
else:
print("输入非法,请重新输入.")
continue

shopping car 1.0的更多相关文章

  1. shopping car 2.0

    #!/usr/bin/env python# -*- coding: utf-8 -*-# @Time : 2018/5/13 0013 10:20# @Author : Anthony.Waa# @ ...

  2. shopping car 3.0

    #!/usr/bin/env python# -*- coding: utf-8 -*-# @File : 购物车3.0.py# @Author: Anthony.waa# @Date : 2018/ ...

  3. python 3.5 购物小程序

    #!/usr/bin/env python #encoding: utf-8 import time import os nowtime = time.strftime('%Y-%m-%d %H:%M ...

  4. 实际情况来看,还是yield很爽

    0 引言 最近公司有一个 php 的项目,要 port 到 node.js 来.我之前没有接触过这个项目,整个项目使用的是 yaf 框架.整个项目流程是调用服务端的业务数据,然后拼装数据,返回给前端: ...

  5. pwnable.tw applestore

    存储结构 0x804B070链表头 struct _mycart_binlist { int *name; //ebp-0x20 int price; //ebp-0x1c struct _mycar ...

  6. python 多个脚本

    1.增删改查haproxy.conf配置文件 1.查询输入:www.oldboy1.com 2.删除输入:{'backend': 'www.oldboy2.org','record':{'server ...

  7. 入门项目 A3 src 主代码

    import json # 调度内置 json 模块,用于数列化输入输出,相比eval,功能更全面,融合度更高from conf import settings # 从配置文件configure (包 ...

  8. R_Studio(关联)对Groceries数据集进行关联分析

    RGui的arules程序包里含有Groceries数据集,该数据集是某个杂货店一个月真实的交易记录,共有9835条消费记录,169个商品 #install.packages("arules ...

  9. 学习Python(一)

    一.Python的基础 1.Python是怎样的语言? 2.Python的安装 Linux安装(python3) yum install -y make zlib zlib-devel gcc-c++ ...

随机推荐

  1. 用一条mysql语句插入多条数据

    这篇文章主要介绍了在mysql中使用一条sql语句插入多条数据,效率非常高,但是原理其实很简单,希望对大家有所帮助 假如有一个数据表A: id name title addtime 如果需要插入n条数 ...

  2. jq 替换DOM layeui 不刷新

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  3. vmware Horizon 7 与远程桌面(mstsc)兼容性问题解决办法

    关于Horizon 7 Agent与远程桌面(mstsc)兼容性问题解决办法 在Horizon 7环境中,在桌面模板安装了Horizon Agent后,就无法直接通过微软的远程桌面(mstsc)工具连 ...

  4. GFS分布式文件系统理论个人总结

    GlusterFS 两种模式 可以通过TCP/IP和RDMA高速网络互连,客户端可通过原生Gluster协议访问数据 没有GlusterFS客户端的可以通过NFS/CIFS标准协议通过存储网关访问数据 ...

  5. [接口管理平台] eoLinker AMS 专业版 V3.5 :加入数据结构管理、通用函数管理、API 快速测试等近 30 项更新

    eoLinker AMS是集API文档管理.API自动化测试.开发协作三位一体的综合API开发管理平台,是中国最大的在线API管理平台.目前eoLinker AMS已经为来自全球的超过两万家企业托管超 ...

  6. while(Thread.activeCount() > 1)

    今天看到深入理解JVM第367页多线程volatile部分照着书本敲着代码发现了一个问题 Thread.activeCount()会一直大于2 public class VolatileTest { ...

  7. 七夕心形demo

    from turtle import * pensize(1) pencolor('red') fillcolor('pink') speed(5) up() goto(-30, 100) down( ...

  8. 1069. The Black Hole of Numbers

    For any 4-digit integer except the ones with all the digits being the same, if we sort the digits in ...

  9. cxGrid主从表删除从表记录的困惑

    cxgrid主从表显示方便直观. varADetailDC: TcxGridDataController;AView: TcxCustomGridTableView; with cxgrdbndtbl ...

  10. sqlserver日志文件太大解决方法

    SQL Server 的事务日志意外增大或充满的处理方法 事务日志文件Transaction Log File是用来记录数据库更新情况的文件,扩展名为ldf. 在 SQL Server 7.0 和 S ...