In [1]:
assert True, "This is an assert statement"

In [2]:
num = 2.003

In [3]:
assert num > 2, "value must be greater than 2"

In [4]:
assert num < 2.001, "value must be smaller than 2.001"


---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-4-e973356ceb20> in <module>()
----> 1 assert num < 2.001, "value must be smaller than 2.001"

AssertionError: value must be smaller than 2.001

In [9]:
def temp_c_to_k(temp_in_c):
    """Convert temperature from C to K"""
    temp_in_k = temp_in_c + 273.15
    assert temp_in_k > 0 , "K must be positive"
    return temp_in_k

In [10]:
print(temp_c_to_k(-300))


---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-10-7fa0efd3f2d8> in <module>()
----> 1 print(temp_c_to_k(-300))

<ipython-input-9-ad5f550c0acf> in temp_c_to_k(temp_in_c)
      2     """Convert temperature from C to K"""
      3     temp_in_k = temp_in_c + 273.15
----> 4     assert temp_in_k > 0 , "K must be positive"
      5     return temp_in_k

AssertionError: K must be positive

In [ ]: