简单算法

简介: python 简单算法
def discount(size, count):
    price_8oz = 1.20
    price_12oz = 1.75
    price_12oz_discount = 1.35
    if size == 8:
        return price_8oz * count
    elif size == 12:
        if count <= 4:
            return price_12oz * count
        elif count > 4:
            # divmod() divides one number by another and returns both the number of times
            #     the second number fits into the first, but also the remainder.
            # Here we calculate how many times five goes into the customer order 
            #     and how many extra cups are left over.
            fivecount, remainder = divmod(count, 5)
            return price_12oz_discount * fivecount * 5 + 1.75 * remainder
# Here we test the code to make sure that it works across several iterations of five counts
#    with 12 ounce cups.
for count in range(2, 12):
    print('count:', count, 'cost:', discount(12, count))
相关文章
|
存储 缓存 固态存储
SSD的原理和结构简介
SSD如淡雅之兰花,寻求内外统一,内涵与外在俱佳,除了英俊潇洒的外表,内在的魅力同样不可抵挡。
|
2月前
|
人工智能 编解码 JSON
AI 漫剧动态视频工程化生产实战:图生视频工作流、时序稳定性、显存调优与完整流水线落地
本文详解AI漫剧图生视频的底层技术与工程化实践:基于Wan2.2-Animate(DiT+MoE+3D-VAE)架构,强调低运动强度(motion 3–6)、短片段(3–6秒)、模块化工作流(6大可调试模块)、时序防抖及严格资产版本管理,兼顾效果稳定与消费级硬件可行性。
502 0
|
关系型数据库 MySQL 数据库
【MySQL】手把手教你MySQL数据同步
【MySQL】手把手教你MySQL数据同步
|
存储 关系型数据库 MySQL
B树和B+树的区别
B树和B+树的区别
923 1
|
机器学习/深度学习 分布式计算 供应链
Hadoop在特定行业中的应用实例
【8月更文第28天】Hadoop是一个强大的分布式计算框架,能够处理大规模数据集。由于其高可扩展性和成本效益,Hadoop被广泛应用于多个行业中,如金融、医疗保健和零售等。本文将探讨Hadoop在这些行业的具体应用场景和一些成功案例。
958 0
|
JavaScript 前端开发
NodeJs——error:03000086:digital envelope routines::initialization error
NodeJs——error:03000086:digital envelope routines::initialization error
544 0
|
存储 缓存 资源调度
npm、yarn与pnpm详解
npm、yarn与pnpm详解
877 0
|
监控 网络协议 Java
Nifi 安装-1 | 学习笔记
快速学习 Nifi 安装-1
1344 0
Nifi 安装-1  |  学习笔记
|
存储 SQL 机器学习/深度学习
基于SLS平台与日志审计构建Cloud SIEM方案
本文介绍如何基于SLS平台与日志审计构建Cloud SIEM方案。
2546 0