shopping_cart
#!/usr/bin/env python
# -*- coding: utf-8 -*-
print('欢迎土豪光临随心所欲旗舰店')
user_money = int(input('老板,请输入你拥有的总资产:'))
shopping_list = []
shopping_car = {}
chose_list = []
out = '谢谢惠顾小店'
goods = [
{"name": "电脑", "price": 1999},
{"name": "鼠标", "price": 10},
{"name": "游艇", "price": 20},
{"name": "美女", "price": 998},
]
# 向用户展示商品
for i in enumerate(goods):
shop_id = i[0]
shop_name = i[1].get('name')
shop_money = i[1].get('price')
print('商品id:', shop_id, '商品:', shop_name, '售价:', shop_money)
enterone = input('请问你需要选购么?y/n')
if enterone.lower() and enterone == 'y':
print('请您输入你想要的商品id,选购完毕离开请输入Q/q')
while True:
choose = input('上帝的选择:')
#if int(choose) > 3:
# print('亲爱的上帝,您输入的数字不在商品列表中,请重新输入')
# continue
#else:
# pass
if choose.lower() and choose == 'q':
break
elif int(choose) > int(len(goods)):
print('亲爱的上帝,您输入的数字不在商品列表中,请重新输入')
continue
else:
now_money = user_money
user_money = user_money - goods[int(choose)].get('price')
if now_money <= goods[int(choose)].get('price'):
print('您的账号余额:',now_money,'购买:',goods[int(choose)],'还差:',user_money)
#print('加入购物车失败!')
print("""
1 充值
2 删减购物车
""")
now_chose = input('请选择:1/2')
if int(now_chose) == 1:
recharge_money = int(input('请输入充值金额:'))
user_money = user_money + recharge_money
print('您的账号金额:',user_money)
elif int(now_chose) == 2:
for w in enumerate(chose_list):
print(w)
while True:
remove_list = input('请输入您想要删除的商品id:退出请输入Q/q')
now_list = int(len(chose_list))
if remove_list.lower() and remove_list == 'q':
print('已成功返回上一层:')
break
elif int(remove_list) < now_list:
g = None
e = chose_list[int(remove_list)]
for g in enumerate(goods):
if str(e) in g[1].get('name') :
user_money = now_money + g[1].get('price')
print('您现在的余额为:',user_money)
del chose_list[int(remove_list)]
print(chose_list)
else:
print('输入有误请重新输入') else:
chose_list.append(goods[int(choose)].get('name'))
print(chose_list)
print(chose_list)
else:
print('请稍候....,现在系统为你自动结算,')
#pass
print('您的账号余额:', user_money)
print('您购买的商品:',chose_list)
shopping_cart的更多相关文章
- Python学习笔记(5)practice:shopping_cart
2019-02-27 原代码: money = int(input("请输入金额:")) list = ["phone", "clothes" ...
- python之信用卡ATM(第五天)
本节作业 作业需求: 模拟实现一个ATM + 购物商城程序 额度 15000或自定义 实现购物商城,买东西加入 购物车,调用信用卡接口结账 可以提现,手续费5% 每月22号出账单,每月10号为还款日, ...
- python3 购物程序
要求: 一.启动程序后,选择是商家还是用户 1.选择商家用户 输入用户名,密码进入 选择增加商品及价格:格式: 商品名称 价格 选择编辑商品及价格:根据提示进行操作 2.选择用户 输入用户名,密码进 ...
- 基于python网络编程实现支持购物、转账、存取钱、定时计算利息的信用卡系统
一.要求 二.思路 1.购物类buy 接收 信用卡类 的信用卡可用可用余额, 返回消费金额 2.信用卡(ATM)类 接收上次操作后,信用卡可用余额,总欠款,剩余欠款,存款 其中: 1.每种交易类型不单 ...
- Python之路 day2 购物车小程序1
#Author:ersa ''' 程序:购物车程序 需求: 启动程序后,让用户输入工资,然后打印商品列表 允许用户根据商品编号购买商品 用户选择商品后,检测余额是否够,够就直接扣款,不够就提醒 可随时 ...
- coffeescript 1.8.0 documents
CoffeeScript is a little language that compiles into JavaScript. Underneath that awkward Java-esque ...
- git workflow常用命令
git init git status git add readme.txt git add --all Adds all new or modified files git comm ...
- 以优美方式编写JavaScript代码
英文原文:CoffeeScript: The beautiful way to write JavaScript 我用 JavaScript 编程很多年了,写了大量的 JavaScript 代码,即便 ...
- python基础:三层循环
三层循环基本演示: break_flag = False #标记1 break_flag2 = False #标记2 break_flag3 = False #标记3 while not break_ ...
随机推荐
- MySQL二进制日志总结
二进制日志简单介绍 MySQL的二进制日志(binary log)是一个二进制文件,主要用于记录修改数据或有可能引起数据变更的MySQL语句.二进制日志(binary log)中记录了对MySQL数据 ...
- 解决Appium无元素可选的如何定位
1.首先我们看看要定位的东西,我要定位的就是折让率上图自己看 写代码: AndroidElement element = driver.findElementByAndroidUIAutomato ...
- Mycat中的核心概念
Mycat中的核心概念 Mycat中的核心概念 1.数据库中间件 Mycat 是一个开源的分布式数据库系统,但是由于真正的数据库需要存储引擎,而 Mycat 并没有 存储引擎,所以并 ...
- 老李分享:Eclipse中开发性能测试loadrunner脚本
老李分享:Eclipse中开发性能测试loadrunner脚本 前篇我分享了如何用loadrunner搭建javauser的性能测试脚本环境,本次我来告诉大家如何在eclipse开发loadrunne ...
- Oracle常见错误集锦
1.ORA-12560:TNS:协议适配器错误 OracleService<SID>服务没有启动 2. ORA-12541:TNS:无监听程序 Oracle<ORACLE_HOME& ...
- win8如何显示文件后缀名
按快捷键[WIN+X]然后点击[文件资源管理器] 进入我的电脑后点击菜单栏的[查看] 查看下面有一个[文件扩展名]把前面那个勾,勾上就可以显示后缀名了. 同样的道理取消勾就是隐藏后缀名. ...
- Javascript删除数组中指定值的元素
Array.prototype.remove = function(index){ if(isNaN(index) || index > this.length){return false;} ...
- JSP自定义不带属性和标签体的简单标签
1. 新建HelloTag类 2. 添加额外的Jar包 (1). 右键项目 -> Build Path -> Configure Build Path -> Libraries -& ...
- $_GET
POST GET ,是提交表单的两种方式,GET传值就用$_GET获取,POST提交表单就用$_POSTpost与get的区别是一个在地址栏显示参数,另一个不显示 如果地址是这样:http://zhi ...
- VS Code 的常用快捷键
VS Code 的常用快捷键和插件 一.vs code 的常用快捷键 1.注释: a) 单行注释:[ctrl+k,ctrl+c] 或 ctrl+/ b) 取消单行注释:[ctrl+k,ctrl+u] ...