zoukankan      html  css  js  c++  java
  • assert 代码自检查

    def apply_discount(price, discount):
        updated_price = price * (1 - discount)
        assert 0 <= updated_price <= price, 'price should be greater or equal to 0 and less or equal to original price'
        return updated_price
    print apply_discount(100,0.2)
    
    C:Python27python.exe "C:/Users/TLCB/PycharmProjects/untitled2/python study/t22.py"
    80.0
    
    
    def apply_discount(price, discount):
        updated_price = price * (1 - discount)
        assert 0 <= updated_price <= price, 'price should be greater or equal to 0 and less or equal to original price'
        return updated_price
    print apply_discount(100,2)
    
    C:Python27python.exe "C:/Users/TLCB/PycharmProjects/untitled2/python study/t22.py"
    Traceback (most recent call last):
      File "C:/Users/TLCB/PycharmProjects/untitled2/python study/t22.py", line 6, in <module>
        print apply_discount(100,2)
      File "C:/Users/TLCB/PycharmProjects/untitled2/python study/t22.py", line 4, in apply_discount
        assert 0 <= updated_price <= price, 'price should be greater or equal to 0 and less or equal to original price'
    AssertionError: price should be greater or equal to 0 and less or equal to original price
  • 相关阅读:
    吴恩达深度学习作业
    @Resource
    Hadoop 大数据平台常用组件端口号汇总
    HDFS读写分析
    HDFS基础之NN、SNN、DN
    teamviewer早期版本下载链接
    linux权限说明
    关于Mac VMFusion Centos7虚拟机网络的配置
    mysql开启远程授权
    Java 空值判断的工具类
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13348348.html
Copyright © 2011-2022 走看看