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
  • 相关阅读:
    BZOJ 3522 Hotel
    BZOJ 1864 三色二叉树
    396595
    CodeForces
    CodeForces
    CodeForces
    E. 数字串
    算术基本定理总结
    Cyclic Nacklace 杭电3746
    Period
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13348348.html
Copyright © 2011-2022 走看看