Day 16 购物车

#! /usr/bin/env python
# -*- coding: utf-8 -*-
# __author__ = "DaChao"
# Date: 2017/6/7

#! /usr/bin/env python
# -*- coding: utf-8 -*-
# __author__ = "DaChao"
# Date: 2017/6/10

‘‘‘
要求用户输入总资产,例如:2000
显示商品列表,让用户根据序号选择商品,加入购物车
购买,如果商品总额大于总资产,提示账户余额不足,否则,购买成功。
附加:可充值、某商品移除购物车
goods = [
    {"name": "电脑", "price": 1999},
    {"name": "鼠标", "price": 10},
    {"name": "游艇", "price": 20},
    {"name": "美女", "price": 998},
]
‘‘‘

def shangpin():
    ‘‘‘
    打印商品列表及序号,并价格赋值
    :return:
    ‘‘‘
    num = 1
    for n_p in goods:
        print(num,n_p["name"],n_p[‘price‘])
        p_goods.append(n_p[‘price‘])
        num+=1

def choose_1():
    ‘‘‘
    打印购物选择
    :return:
    ‘‘‘
    tips_1 = ["Continue shopping!", "Go payment!"]
    num = 1
    for n_p in tips_1:
        print(num,tips_1[num-1])
        num+=1

def choose_2():
    ‘‘‘
    打印金额不足选择
    :return:
    ‘‘‘
    tips_2 = ["Go recharge!","Go to remove goods!"]
    num = 1
    print("Your money are not enough!")
    for n_p in tips_2:
        print(num, tips_2[num - 1])
        num += 1

def goods_list():
    ‘‘‘
    显示购物车功能
    :return:
    ‘‘‘
    if goods_1 != 0:
        print("已购买电脑数量: ",goods_1)
    if goods_2 != 0:
        print("已购买鼠标数量: ",goods_2)
    if goods_3 != 0:
        print("已购买游艇数量: ",goods_3)
    if goods_4 != 0:
        print("已购买美女数量: ",goods_4)

if __name__ == ‘__main__‘:
    goods = [
        {"name": "电脑", "price": 1999},
        {"name": "鼠标", "price": 10},
        {"name": "游艇", "price": 20},
        {"name": "美女", "price": 998},
    ]
    p_goods = []
    money_bsum = 0
    g_goods = []
    goods_1 = 0
    goods_2 = 0
    goods_3 = 0
    goods_4 = 0
    num = 0

    money_sum = int(input("Please input your total money in your wallet: "))

    tag_1 = True
    while tag_1:                  #商品购物
        shangpin()
        num = int(input("Please choose your favorite goods of id: "))
        if num in range(1,5):       #选择商品,购物总价叠加,并加入新购物列表,以便移除.
            money_bsum = money_bsum + int(p_goods[num-1])
            if num == 1:
                goods_1 += 1
                print("电脑 加入购物车!目前数量: ", goods_1)
            elif num == 2:
                goods_2 += 1
                print("鼠标 加入购物车!目前数量: ", goods_2)
            elif num == 3:
                goods_3 += 1
                print("游艇 加入购物车!目前数量: ", goods_3)
            elif num == 4:
                goods_4 += 1
                print("美女 加入购物车!目前数量: ", goods_4)
        else:
            print("Please input correct ID.")
        choose_1()
        choose_id = input("1 & 2 ?")
        if choose_id == "2":
            tag_1 = False

    tag_2 = True
    while tag_2:                 #支付选择,如果余额不足,充值或移除商品至支付成功。
        if money_bsum <= money_sum:
            print("Pay successful!")
            tag_2 = False
        else :
            choose_2()
            choose_id = input("1 & 2 ?")
            if choose_id == "1":
                money_sum += int(input("Please input your recharge money: "))
            elif choose_id == "2":
                goods_list()
                shangpin()
                while tag_2:
                    num_del = int(input(print("Please choose your del goods of id: ")))
                    if num_del == 1 and goods_1 != 0:
                        goods_1 -= 1
                        money_bsum -= 1999
                        if money_bsum <= money_sum:
                            tag_2 = False
                    elif num_del == 2 and goods_2 != 0:
                        goods_2 -= 1
                        money_bsum -= 10
                        if money_bsum <= money_sum:
                            tag_2 = False
                    elif num_del == 3 and goods_3 != 0:
                        goods_3 -= 1
                        money_bsum -= 20
                        if money_bsum <= money_sum:
                            tag_2 = False
                    elif num_del == 1 and goods_4 != 0:
                        goods_4 -= 1
                        money_bsum -= 998
                        if money_bsum <= money_sum:
                            tag_2 = False
                print("You can offord your shopping!")
时间: 2024-12-19 00:34:24

Day 16 购物车的相关文章

便是见到前方那

以可得量力而凌厉刀芒横扫http://weibo.com/2015.09.16/p/1001603887144312655250http://weibo.com/2015.09.16/p/1001603887144321088567http://weibo.com/2015.09.16/p/1001603887144325238274http://weibo.com/2015.09.16/p/1001603887144325282921http://weibo.com/2015.09.16/p/

对于这黑马之会

是想不出究竟还只是区区一角啊http://weibo.com/2015-09.16/p/1001603887574727917787http://weibo.com/2015-09.16/p/1001603887574727946828http://weibo.com/2015-09.16/p/1001603887574732112097http://weibo.com/2015-09.16/p/1001603887574732112103http://weibo.com/2015-09.16/

2019.5.16 课后练习。简易购物车程序

根据之前看过的知识点,以自己的思路先写出了一个程序,后续继续老师的操作再进行优化. 1 salary = int(input("请输入您的工资(单位 元):")) 2 3 print("以下是可购清单:") 4 5 shopping_list = ['','iphone','computer','book','apple_juice','bread','cake']#商品列表 6 commodity_prices = [0,6000,7000,2,3,3,5] #商

16款购物商城添加购物车源码特效

jquery仿天猫商城点击加入购物车按钮商品动画飞到购物车里面效果 jquery文本框选择器_商品尺寸选择和商品价格选择添加到购物车 jQuery商品购物车自动计算金额总数表单提交 jquery添加购物车复选框,全选,反选,取消,商品数量统计价格 jquery商品飞入购物车动画效果代码 jquery数量加减插件_购物车商品数量加减_商品数字加减效果代码 html5弹出窗口点击购物车弹出商品清单列表代码 jquery数量加减插件制作购物车数量加减功能代码 jQuery仿天猫加入购物车代码点击商品飞

12月16日 增加一个购物车内product数量的功能, 自定义method,在helper中定义,计算代码Refactor到Model中。

仿照Rails实战:购物网站 教材:5-6 step5:计算总价,做出在nav上显示购物车内product的数量. 遇到的?: 1. <% sum = 0 %> <% current_cart.cart_items each do |cart_item| %> <% if cart_item.product.price.present? %> <% sum = sum + cart_item.quantity * cart_item.product.price %

java web 开发 购物车功能的实现

为了方便自己以后复习,所以写的比较仔细,记录下自己的成长..... 既然是做购物车,那么前提条件是首先需要一系列商品,也就是要建一个实体,这里建了一个商品表. 通过查询在浏览器上显示 基本显示已经做好了,现在进入我们的重头戏,Servlet 点击放入购物车时,将访问Servlet 购物车代码 1 package com.servlet; 2 3 import java.io.IOException; 4 import java.io.PrintWriter; 5 import java.util

Python 购物车

Python 购物车 需求 用户名和密码存放于文件中,格式为:xxx|xxx 启动程序后,先登录,登录成功则让用户输入工资,然后打印商品列表,失败则重新登录,超过三次则退出程序 允许用户根据商品编号购买商品 用户选择商品后,检测余额是否够,够就直接扣款,不够就提醒 可随时退出,退出时,打印已购买商品和余额 流程图 Python代码实现 1 #! /usr/bin/env python 2 # -*- coding: utf-8 -*- 3 # 商城购物车 4 product_list = [ 5

购物车css样式效果

1 <!DOCTYPE html> 2 <html> 3 4 <head> 5 <meta charset="UTF-8"> 6 <title>购物车效果</title> 7 8 <style> 9 body { 10 background: black; 11 } 12 13 nav { 14 width: 120px; 15 height: 40px; 16 background: #ccc; 17

贝塞尔曲线实现的购物车添加商品动画效果

效果图如下: 1.activity_main.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/rly_bezier_curve_shopping_cart" android:layout_w