#!/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