zoukankan      html  css  js  c++  java
  • shopping car 1.0

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


  • 相关阅读:
    什么是em?
    数据结构与算法:快速排序
    flex中flexshrink的理解
    前端的padding是参照父元素的宽度还是高度?
    子元素的border不能通过百分比设置的
    数据库去重的简易方法
    windows2003 iis6.0站点打不开,找不到服务器或 DNS 错误。
    常用WebServices返回数据的4种方法比较
    手机身份证IP地址开放接口(很实用哦)
    从创业失败中学到的七条教训
  • 原文地址:https://www.cnblogs.com/ipyanthony/p/9018516.html
Copyright © 2011-2022 走看看